{"id":3266,"date":"2023-03-10T14:09:50","date_gmt":"2023-03-10T13:09:50","guid":{"rendered":"https:\/\/www.microdata.no\/?post_type=eksempel&#038;p=3266"},"modified":"2023-08-18T13:31:06","modified_gmt":"2023-08-18T12:31:06","slug":"diff-in-diff-analysis","status":"publish","type":"eksempel","link":"https:\/\/www.microdata.no\/en\/eksempel\/diff-in-diff-analysis\/","title":{"rendered":"Diff-in-diff analysis"},"content":{"rendered":"\n<p>In the example below, a diff-in-diff analysis is run.<\/p>\n\n\n\n<p>First, a random sample of 100,000 individuals is drawn. This is optional, it is entirely possible to run the analysis on full populations. A panel data set is then created for this sample using <code>import-panel<\/code>, and data is imported for the years 2018 &#8211; 2021. Afterwards, the panel data set is balanced by deleting all observations with at least one missing value (optional).<\/p>\n\n\n\n<p>The group variable is then coded, using women as the treatment group and men as the control group. The processing date is set for 2020. <\/p>\n\n\n\n<p>Finally, the command <code>regress-panel-diff<\/code> is executed, and you get the diff-in-diff value (ATET) -1991.77 when you control for marital status = married, place of residence = Oslo, and educational level equal to a master&#8217;s degree or higher. The ATET value is not significant in this case.<\/p>\n\n\n<div id=\"rose-block_83fe88f469d407405aa119baaa3a77ff\" class=\"rose-code codeblock-wrapper\">\n<pre tabindex=\"0\" class=\"codeblock\"><code>require no.ssb.fdb:23 as db\r\n\r\n\/\/Create a random sample of 100000 individuals\r\ncreate-dataset population\r\nimport db\/BEFOLKNING_KJOENN as gender\r\nsample 100000 3322\r\nclone-units population paneldata\r\n\r\n\/\/Create a panel dataset for the random population\r\nuse paneldata\r\nimport-panel db\/INNTEKT_LONN db\/SIVSTANDFDT_SIVSTAND db\/BOSATTEFDT_BOSTED db\/BEFOLKNING_KJOENN db\/NUDB_BU 2018-01-01 2019-01-01 2020-01-01 2021-01-01\r\nrename INNTEKT_LONN wage\r\nrename SIVSTANDFDT_SIVSTAND civstat\r\nrename BOSATTEFDT_BOSTED municipality\r\nrename BEFOLKNING_KJOENN gender\r\nrename NUDB_BU edu\r\n\r\n\/\/Balance the panel dataset\r\ndrop if sysmiss(wage) | sysmiss(civstat) | sysmiss(municipality) | sysmiss(gender) | sysmiss(edu)\r\n\r\n\/\/Create group and treatment variables (required)\r\ngenerate group = 0\r\nreplace group = 1 if gender == '2'\r\n\r\ngenerate treatment = 0\r\nreplace treatment = 1 if year(date@panel) >= 2020\r\n\r\n\/\/Recode other explanatory variables\r\ngenerate married = 0\r\nreplace married = 1 if civstat == '2'\r\n\r\ngenerate oslo = 0\r\nreplace oslo = 1 if municipality == '0301'\r\n\r\ngenerate high_edu = 0\r\nreplace high_edu = 1 if substr(edu,1,1) == '7' | substr(edu,1,1) == '8'\r\n\r\n\/\/Run diff-in-diff analysis\r\nsummarize-panel wage if group == 1\r\nsummarize-panel wage if group == 0\r\n\r\nregress-panel-diff wage group treatment married oslo high_edu<\/code><\/pre>\n<\/div>","protected":false},"parent":0,"menu_order":129,"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-3266","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>Diff-in-diff analysis - 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\/diff-in-diff-analyse\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Diff-in-diff analysis - microdata.no\" \/>\n<meta property=\"og:description\" content=\"In the example below, a diff-in-diff analysis is run. First, a random sample of 100,000 individuals is drawn. This is optional, it is entirely possible to run the analysis on full populations. A panel data set is then created for this sample using import-panel, and data is imported for the years 2018 &#8211; 2021. Afterwards,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.microdata.no\/eksempel\/diff-in-diff-analyse\/\" \/>\n<meta property=\"og:site_name\" content=\"microdata.no\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-18T12:31:06+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\\\/diff-in-diff-analyse\\\/\",\"url\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/diff-in-diff-analyse\\\/\",\"name\":\"Diff-in-diff analysis - microdata.no\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/#website\"},\"datePublished\":\"2023-03-10T13:09:50+00:00\",\"dateModified\":\"2023-08-18T12:31:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/diff-in-diff-analyse\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/diff-in-diff-analyse\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.microdata.no\\\/eksempel\\\/diff-in-diff-analyse\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Hjem\",\"item\":\"https:\\\/\\\/www.microdata.no\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Diff-in-diff analysis\"}]},{\"@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":"Diff-in-diff analysis - 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\/diff-in-diff-analyse\/","og_locale":"en_US","og_type":"article","og_title":"Diff-in-diff analysis - microdata.no","og_description":"In the example below, a diff-in-diff analysis is run. First, a random sample of 100,000 individuals is drawn. This is optional, it is entirely possible to run the analysis on full populations. A panel data set is then created for this sample using import-panel, and data is imported for the years 2018 &#8211; 2021. Afterwards,...","og_url":"https:\/\/www.microdata.no\/eksempel\/diff-in-diff-analyse\/","og_site_name":"microdata.no","article_modified_time":"2023-08-18T12:31:06+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\/diff-in-diff-analyse\/","url":"https:\/\/www.microdata.no\/eksempel\/diff-in-diff-analyse\/","name":"Diff-in-diff analysis - microdata.no","isPartOf":{"@id":"https:\/\/www.microdata.no\/#website"},"datePublished":"2023-03-10T13:09:50+00:00","dateModified":"2023-08-18T12:31:06+00:00","breadcrumb":{"@id":"https:\/\/www.microdata.no\/eksempel\/diff-in-diff-analyse\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.microdata.no\/eksempel\/diff-in-diff-analyse\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.microdata.no\/eksempel\/diff-in-diff-analyse\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Hjem","item":"https:\/\/www.microdata.no\/en\/"},{"@type":"ListItem","position":2,"name":"Diff-in-diff analysis"}]},{"@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\/3266","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=3266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}