{"id":1228,"date":"2022-02-11T14:57:39","date_gmt":"2022-02-11T13:57:39","guid":{"rendered":"https:\/\/microdata.spirehost.no\/?post_type=eksempel&#038;p=1228"},"modified":"2023-10-27T16:39:19","modified_gmt":"2023-10-27T15:39:19","slug":"create-dummy-variables-by-using-the-recode-command","status":"publish","type":"eksempel","link":"https:\/\/www.microdata.no\/en\/eksempel\/create-dummy-variables-by-using-the-recode-command\/","title":{"rendered":"Create dummy variables by using the recode command"},"content":{"rendered":"\n<p>There is more than one way to make dummy variables (values 1 and 0). Perhaps the most basic way is by using the <code>generate<\/code> and <code>replace<\/code> commands (see one of the other examples).<\/p>\n\n\n\n<p>An alternative way of making dummy variables is by using the <code>destring<\/code> and <code>recode<\/code> commands as illustrated in the example below.<\/p>\n\n\n\n<p>The variable <code>gender<\/code> takes the values &#8216;1&#8217; and &#8216;2&#8217; representing the values &#8220;Male&#8221; and &#8220;Female&#8221; respectively. The result of the procedure is a variable containing the values 1 and 0 representing male and female (= not male) respectively.<\/p>\n\n\n\n<p>Since <code>recode<\/code> only accepts numerical valueformats, one must first convert from alfanumerical through the <code>destring<\/code> command. However, this is not necessary if the variable is numerical to begin with.<\/p>\n\n\n<div id=\"rose-block_1559ed264bc265a7b4dae6ac621e17ff\" 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 demography\r\nimport db\/BEFOLKNING_KJOENN as gender\r\n\r\ndestring gender\r\ntabulate gender\r\nrecode gender (2 = 0)\r\nrename gender male\r\n\r\n\/\/Check for correct recoding\r\ntabulate male, nolabels<\/code><\/pre>\n<\/div>\n\n\n<p><\/p>\n","protected":false},"parent":0,"menu_order":14,"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-1228","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>Create dummy variables by using the recode command - 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\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create dummy variables by using the recode command - microdata.no\" \/>\n<meta property=\"og:description\" content=\"There is more than one way to make dummy variables (values 1 and 0). Perhaps the most basic way is by using the generate and replace commands (see one of the other examples). An alternative way of making dummy variables is by using the destring and recode commands as illustrated in the example below. The...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.microdata.no\/eksempel\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/\" \/>\n<meta property=\"og:site_name\" content=\"microdata.no\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-27T15:39:19+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\\\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\\\/\",\"url\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\\\/\",\"name\":\"Create dummy variables by using the recode command - microdata.no\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/#website\"},\"datePublished\":\"2022-02-11T13:57:39+00:00\",\"dateModified\":\"2023-10-27T15:39:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Hjem\",\"item\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create dummy variables by using the recode command\"}]},{\"@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":"Create dummy variables by using the recode command - 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\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/","og_locale":"en_US","og_type":"article","og_title":"Create dummy variables by using the recode command - microdata.no","og_description":"There is more than one way to make dummy variables (values 1 and 0). Perhaps the most basic way is by using the generate and replace commands (see one of the other examples). An alternative way of making dummy variables is by using the destring and recode commands as illustrated in the example below. The...","og_url":"https:\/\/www.microdata.no\/eksempel\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/","og_site_name":"microdata.no","article_modified_time":"2023-10-27T15:39:19+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\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/","url":"https:\/\/www.microdata.no\/eksempel\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/","name":"Create dummy variables by using the recode command - microdata.no","isPartOf":{"@id":"https:\/\/www.microdata.no\/#website"},"datePublished":"2022-02-11T13:57:39+00:00","dateModified":"2023-10-27T15:39:19+00:00","breadcrumb":{"@id":"https:\/\/www.microdata.no\/eksempel\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.microdata.no\/eksempel\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.microdata.no\/eksempel\/lage-dummyvariabel-ved-a-bruke-kommandoen-recode\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Hjem","item":"https:\/\/www.microdata.no\/en\/"},{"@type":"ListItem","position":2,"name":"Create dummy variables by using the recode command"}]},{"@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\/1228","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=1228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}