{"id":1275,"date":"2022-02-11T16:20:04","date_gmt":"2022-02-11T15:20:04","guid":{"rendered":"https:\/\/microdata.spirehost.no\/?post_type=eksempel&#038;p=1275"},"modified":"2023-10-27T16:39:20","modified_gmt":"2023-10-27T15:39:20","slug":"recode-from-country-to-world-region","status":"publish","type":"eksempel","link":"https:\/\/www.microdata.no\/en\/eksempel\/recode-from-country-to-world-region\/","title":{"rendered":"Recode from country to world region"},"content":{"rendered":"\n<p>The example below demonstrates how to recode a variable that contains values \u200b\u200bon country level into world region level. Country level is in many cases too detailed, and it can then be useful to group countries according to Statistics Norway&#8217;s standard for world regions (<a href=\"https:\/\/www.ssb.no\/en\/klass\/klassifikasjoner\/91\/varianter\/1466\">https:\/\/www.ssb.no\/en\/klass\/klassifikasjoner\/91\/varianter\/1466<\/a>).<\/p>\n\n\n\n<p>By using the command <code>destring<\/code> to make the values \u200b\u200bnumeric, the <code>recode<\/code> command may then be used to recode the values. Recode makes it possible, among other things, to recode all values \u200b\u200bwithin an interval into a given value. The recoding takes place sequentially from left to right in the recode expression, which can be used to simplify the coding. In the example below, e.g. the value 1 is assigned to all countries with codes in the intervals 101 &#8211; 141 and 144 &#8211; 158, except those which have already been given the code 2 in the previous parentheses.<\/p>\n\n\n<div id=\"rose-block_b2a8cc3cb6a3224f3b3f29736b8e3d90\" 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\ncreate-dataset population\r\nimport db\/BEFOLKNING_STATUSKODE 2021-01-01 as regstatus\r\nkeep if regstatus == '1'\r\n\r\nimport db\/BEFOLKNING_FODELAND as birthcountry\r\ntabulate birthcountry\r\n\r\n\/\/Create a copy of the birthcountry variable for controle purposes\r\nclone-variables birthcountry -> birthcountry_orig\r\n\r\n\/\/Recode birth country into world region - first use destring to turn the value format into numeric (required when using recode command)\r\ndestring birthcountry\r\nrecode birthcountry (111 120 138 139 140 148 155 156 159\/164 = 2) (101\/141 144\/158 = 1) (203\/393 = 3) (143 404\/578 = 4) (612 684 = 5) (601\/775 = 6) (802\/840 = 7) (980 = 8) (990 = 9)\r\n\r\ndefine-labels wregion 0 'Norway' 1 'EU\/EEA' 2 'European countries outside the EU' 3 'Africa' 4 'Asia with Turkey' 5 'North America' 6 'South and Central America' 7 'Oceania' 8 'Stateless' 9 'Unknown'\r\nassign-labels birthcountry wregion\r\n\r\ntabulate birthcountry\r\ntabulate birthcountry_orig birthcountry<\/code><\/pre>\n<\/div>","protected":false},"parent":0,"menu_order":40,"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-1275","eksempel","type-eksempel","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Recode from country to world region - 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\/eksempel\/omkode-fra-land-til-verdensregion\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Recode from country to world region - microdata.no\" \/>\n<meta property=\"og:description\" content=\"The example below demonstrates how to recode a variable that contains values \u200b\u200bon country level into world region level. Country level is in many cases too detailed, and it can then be useful to group countries according to Statistics Norway&#8217;s standard for world regions (https:\/\/www.ssb.no\/en\/klass\/klassifikasjoner\/91\/varianter\/1466). By using the command destring to make the values \u200b\u200bnumeric,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.microdata.no\/eksempel\/omkode-fra-land-til-verdensregion\/\" \/>\n<meta property=\"og:site_name\" content=\"microdata.no\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-27T15:39:20+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\\\/eksempel\\\/omkode-fra-land-til-verdensregion\\\/\",\"url\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/omkode-fra-land-til-verdensregion\\\/\",\"name\":\"Recode from country to world region - microdata.no\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/#website\"},\"datePublished\":\"2022-02-11T15:20:04+00:00\",\"dateModified\":\"2023-10-27T15:39:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/omkode-fra-land-til-verdensregion\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/omkode-fra-land-til-verdensregion\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/omkode-fra-land-til-verdensregion\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Hjem\",\"item\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Recode from country to world region\"}]},{\"@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":"Recode from country to world region - 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\/eksempel\/omkode-fra-land-til-verdensregion\/","og_locale":"en_US","og_type":"article","og_title":"Recode from country to world region - microdata.no","og_description":"The example below demonstrates how to recode a variable that contains values \u200b\u200bon country level into world region level. Country level is in many cases too detailed, and it can then be useful to group countries according to Statistics Norway&#8217;s standard for world regions (https:\/\/www.ssb.no\/en\/klass\/klassifikasjoner\/91\/varianter\/1466). By using the command destring to make the values \u200b\u200bnumeric,...","og_url":"https:\/\/www.microdata.no\/eksempel\/omkode-fra-land-til-verdensregion\/","og_site_name":"microdata.no","article_modified_time":"2023-10-27T15:39:20+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\/eksempel\/omkode-fra-land-til-verdensregion\/","url":"https:\/\/www.microdata.no\/eksempel\/omkode-fra-land-til-verdensregion\/","name":"Recode from country to world region - microdata.no","isPartOf":{"@id":"https:\/\/www.microdata.no\/#website"},"datePublished":"2022-02-11T15:20:04+00:00","dateModified":"2023-10-27T15:39:20+00:00","breadcrumb":{"@id":"https:\/\/www.microdata.no\/eksempel\/omkode-fra-land-til-verdensregion\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.microdata.no\/eksempel\/omkode-fra-land-til-verdensregion\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.microdata.no\/eksempel\/omkode-fra-land-til-verdensregion\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Hjem","item":"https:\/\/www.microdata.no\/en\/"},{"@type":"ListItem","position":2,"name":"Recode from country to world region"}]},{"@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\/1275","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=1275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}