{"id":1283,"date":"2022-02-14T12:06:41","date_gmt":"2022-02-14T11:06:41","guid":{"rendered":"https:\/\/microdata.spirehost.no\/?post_type=eksempel&#038;p=1283"},"modified":"2023-08-18T14:01:16","modified_gmt":"2023-08-18T13:01:16","slug":"how-to-aggregate-data-into-family-level","status":"publish","type":"eksempel","link":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/","title":{"rendered":"How to aggregate data into family level"},"content":{"rendered":"\n<p>Individuals can be linked to a family number that can be used to aggregate data on family level. Individuals belonging to the same family are registered with the same family number which consists of the personal id number of the eldest person in the family.<\/p>\n\n\n\n<p>In the example below, an individual level dataset is first created. It is then filtered down to persons in families consisting of married couples with small children (codevalue 2.1.1). Next, demographical information is imported into the dataset.<\/p>\n\n\n\n<p>In order to create data on family level income, one must first create a new dataset for this purpose (variables of different unit types can not be mixed together in a single dataset). A variable measuring work related income on individual level is then imported into the new dataset, before the <code>collapse(sum)<\/code> command is used to sum income into family level (<code>by(famnr)<\/code>). This results in a dataset with family as unit type.<\/p>\n\n\n\n<p>Finally, family income is merged into the individual level dataset using the <code>merge<\/code> command.<\/p>\n\n\n<div id=\"rose-block_5b8e91edd9a15865231586c7dd2e45a1\" class=\"rose-code codeblock-wrapper\">\n<pre tabindex=\"0\" class=\"codeblock\"><code>\/\/Connect to datastore\r\nrequire no.ssb.fdb:23 as db\r\n\r\n\/\/Create an individual level dataset consisting of persons in families defined by married couples with small children\r\ncreate-dataset persondata\r\nimport db\/BEFOLKNING_REGSTAT_FAMTYP 2021-01-01 as famtype\r\ntabulate famtype\r\nkeep if famtype == '2.1.1'\r\n\r\n\/\/Add demographical information\r\nimport db\/BEFOLKNING_KJOENN as gender\r\nimport db\/BEFOLKNING_FOEDSELS_AAR_MND as birthdate\r\ngenerate age = 2021 - int(birthdate\/100)\r\n\r\nimport db\/BEFOLKNING_KOMMNR_FAKTISK 2021-01-01 as municipality\r\ngenerate county = substr(municipality, 1, 2)\r\n\r\nimport db\/BEFOLKNING_BARN_I_HUSH 2021-01-01 as children\r\n\r\n\r\n\/\/Create dataset for generating family level income (unit type = family)\r\ncreate-dataset familydata\r\nimport db\/BEFOLKNING_REGSTAT_FAMNR 2021-01-01 as famnr\r\nimport db\/INNTEKT_WYRKINNT 2021-01-01 as workincome\r\ncollapse (sum) workincome, by(famnr)\r\nrename workincome familyincome\r\n\r\n\/\/Merge family income into individual level dataset (unit type = individuals)\r\nmerge familyincome into persondata on PERSONID_1\r\n\r\n\/\/Generate family level statistics. The family number consists of the personal id of the eldest person in the family, so by removing individuals with missing family level income, the dataset now has unit type = family. All individual information will be assosiated with the eldest person in the family\r\nuse persondata\r\ndrop if sysmiss(familyincome)\r\n\r\nrename age age_oldest\r\nrename gender gender_oldest\r\n\r\ndefine-labels countytxt '03' Oslo '11' Rogaland '15' 'M\u00f8re og Romsdal' '18' Nordland '30' Viken '34' Innlandet '38' 'Vestfold og Telemark' '42' Agder '46' Vestland '50' Tr\u00f8ndelag '54' 'Troms og Finnmark' '21' Spitsbergen '25' 'Education abroad' '99' Unknown\r\nassign-labels county countytxt\r\n\r\ntabulate county\r\n\r\nhistogram age_oldest, discrete\r\nhistogram children, discrete percent\r\n\r\ntabulate children\r\ntabulate children, cellpct\r\ntabulate children gender_oldest\r\n\r\nsummarize familyincome\r\nbarchart (mean) familyincome, by(county)\r\nbarchart (mean) familyincome, by(children)\r\nhistogram familyincome, freq\r\nhistogram familyincome, by(children) percent<\/code><\/pre>\n<\/div>","protected":false},"parent":0,"menu_order":100,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":""},"class_list":["post-1283","eksempel","type-eksempel","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to aggregate data into family level - microdata.no<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to aggregate data into family level - microdata.no\" \/>\n<meta property=\"og:description\" content=\"Individuals can be linked to a family number that can be used to aggregate data on family level. Individuals belonging to the same family are registered with the same family number which consists of the personal id number of the eldest person in the family. In the example below, an individual level dataset is first...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/\" \/>\n<meta property=\"og:site_name\" content=\"microdata.no\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-18T13:01:16+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/eksempel\\\/how-to-aggregate-data-into-family-level\\\/\",\"url\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/eksempel\\\/how-to-aggregate-data-into-family-level\\\/\",\"name\":\"How to aggregate data into family level - microdata.no\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/#website\"},\"datePublished\":\"2022-02-14T11:06:41+00:00\",\"dateModified\":\"2023-08-18T13:01:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/eksempel\\\/how-to-aggregate-data-into-family-level\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.microdata.no\\\/en\\\/eksempel\\\/how-to-aggregate-data-into-family-level\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/eksempel\\\/how-to-aggregate-data-into-family-level\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Hjem\",\"item\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to aggregate data into family level\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.microdata.no\\\/#website\",\"url\":\"https:\\\/\\\/www.microdata.no\\\/\",\"name\":\"microdata.no\",\"description\":\"Gj\u00f8r det enklere \u00e5 analysere registerdata\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.microdata.no\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to aggregate data into family level - microdata.no","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/","og_locale":"en_US","og_type":"article","og_title":"How to aggregate data into family level - microdata.no","og_description":"Individuals can be linked to a family number that can be used to aggregate data on family level. Individuals belonging to the same family are registered with the same family number which consists of the personal id number of the eldest person in the family. In the example below, an individual level dataset is first...","og_url":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/","og_site_name":"microdata.no","article_modified_time":"2023-08-18T13:01:16+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/","url":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/","name":"How to aggregate data into family level - microdata.no","isPartOf":{"@id":"https:\/\/www.microdata.no\/#website"},"datePublished":"2022-02-14T11:06:41+00:00","dateModified":"2023-08-18T13:01:16+00:00","breadcrumb":{"@id":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.microdata.no\/en\/eksempel\/how-to-aggregate-data-into-family-level\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Hjem","item":"https:\/\/www.microdata.no\/en\/"},{"@type":"ListItem","position":2,"name":"How to aggregate data into family level"}]},{"@type":"WebSite","@id":"https:\/\/www.microdata.no\/#website","url":"https:\/\/www.microdata.no\/","name":"microdata.no","description":"Gj\u00f8r det enklere \u00e5 analysere registerdata","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.microdata.no\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"taxonomy_info":[],"featured_image_src_large":[],"author_info":[],"comment_info":"","_links":{"self":[{"href":"https:\/\/www.microdata.no\/en\/wp-json\/wp\/v2\/eksempel\/1283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.microdata.no\/en\/wp-json\/wp\/v2\/eksempel"}],"about":[{"href":"https:\/\/www.microdata.no\/en\/wp-json\/wp\/v2\/types\/eksempel"}],"wp:attachment":[{"href":"https:\/\/www.microdata.no\/en\/wp-json\/wp\/v2\/media?parent=1283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}