5  Differences in Samples

This document was created on Monday May 22nd to address the main bottle neck of the project: what drives the differences in composition (municipality-years) across our and their samples? The answer lies in missing labor market statistics in their data-set. More specifically, though there are municipality-years with all levels of private employment which are missing in their data, the two-thirds have less than 300 private workers (according to our data). While our data also has some missing municipalities (7 missing municipalities in ours that are not missing in theirs), they have 1122 missing municipalities (that are not missing in ours).

The next step is to review Chapter 4 and include a section where we look deeper into missing data for their raw data input data-sets.

5.1 How is the analysis structured? What is important to consider?

Project Structure

The analysis is structed in three phases: pre-cleaning, cleaning and output creation. First, we have the pre-cleaning files. These are not available in their documentation and are responsible for cleaning the input data-sets. Second, we have the cleaning file, which does all of the relevant cleaning. Since there are no additional modifications done to the data outside of a preserve-restore code chunk, we can save the data from the cleaning section and apply it to the output creation files. Lastly, we have the output creation files, which take in the clean data and create the visualizations available in the paper.

We focus on the cleaning codes. Specifically, we compare and contrast the state of the data-set at different points in their and our cleaning codes. In order to avoid any unnecessary differences across cleaning methodologies, we adapt their cleaning code for our data. At the same point in each code, we create 4 “snapshots” of number of yearly observations in each data-set. Snapshot 1 is taken once all of the relevant data is loaded in. Snapshot 2 is taken once observations for irrelevant (and boundary) years and observations with missing population & lagged population estimates are removed. Snapshot 3 is taken once we remove municipalities with missing private or public sector employment. Snapshot 4 is taken right before saving the data-set. Since we do not consider public employment in our data-set (for the purposes of the current output), we only drop observations with missing private sector employment. To get an equivalent comparison with their data, we create a version of their code (and data) with this looser constraint and see very little difference in outcomes.

5.2 How many observations do our and their data-sets have?

For starters, we start with the output data-sets to get a sense of what the major differences in observations are. Below we create two plots.

First, we compare the number of observations in our output data-set with theirs, for all of the relevant years. While the number of observations in our data varies little over time, the same cannot be said about their data-set.

Second, we compare the number of observations in their data-set with a merged version of both data-sets. The objective here is to see whether there are many mutually exclusive municipality-years across the samples. Since the OurAndTheirs series is very similar in shape to Our series, their data-set must be lacking observations (rather than ours being larger but equally lacking).

Code
ours_with_theirs <- "C:/Users/alckm/Dropbox/EEMT/subprojects/transfers_replication/data/processing/our_replication_data_for_figures_both_munyears.dta" %>% 
  haven::read_dta() %>% as.data.table()

ours <- "C:/Users/alckm/Dropbox/EEMT/subprojects/transfers_replication/data/processing/our_replication_data_for_figures.dta" %>% 
  haven::read_dta() %>% as.data.table()

theirs <-  "C:/Users/alckm/Dropbox/EEMT/subprojects/transfers_replication/data/processing/main_exact_data.dta" %>% 
  haven::read_dta() %>% as.data.table()

our_with_theirs_obsyear <- ours_with_theirs %>%
  #.[`_merge`==3] %>% 
  .[, .N, year] %>% rename(., OurAndTheirs=N)

our_obsyear <- ours %>% 
  .[, .N, year] %>% rename(., Our=N)

their_obsyear <- theirs %>% 
  .[, .N, year] %>% rename(., Their=N)
Code
merge(our_obsyear, their_obsyear, "year", all=T) %>% 
  melt.data.table(id.vars = c("year")) %>% 
  ggplot(aes(x=year, y= value, color=variable)) + 
  geom_point() + 
  geom_line() + 
  xlab("Year") + 
  ylab("Observations") + 
  theme_bw()

Number of observations in each data-set per year
Code
merge(our_with_theirs_obsyear, their_obsyear, "year", all=T) %>% 
  melt.data.table(id.vars = c("year")) %>% 
  ggplot(aes(x=year, y= value, color=variable)) + 
  geom_point() + 
  geom_line() + 
  xlab("Year") + 
  ylab("Observations")  + 
  theme_bw()

Number of observations in each data-set per year

5.3 Running Our and Their data cleaning files, line by line

As was mentioned above, we create four snapshots of the data as it transits through the cleaning files. Since the original cleaning file drops missing public (pubn) and private (privn) municipality-year employment, but the figures only require the latter; we create two additional snapshots (alternate 3 and alternate 4) for their cleaning file, where we only drop missing private employment.

Below, we present this data in two ways. First, we present two tables, one for the tabulations tab year in Our data and one for tabulations in their data tab year.

To get a better sense of what these look like, we create visualizations, which are further explained below. These are instrumental in detecting what the underlying issue is.

Code
# ours -----
check_point1_our <- "
 year | Freq. | Percent | Cum.
2002 | 5533 | 5.55 | 5.55
2003 | 5532 | 5.55 | 11.10
2004 | 5532 | 5.55 | 16.65
2005 | 5536 | 5.55 | 22.20
2006 | 5536 | 5.55 | 27.76
2007 | 5536 | 5.55 | 33.31
2008 | 5536 | 5.55 | 38.86
2009 | 5537 | 5.55 | 44.42
2010 | 5537 | 5.55 | 49.97
2011 | 5537 | 5.55 | 55.53
2012 | 5537 | 5.55 | 61.08
2013 | 5542 | 5.56 | 66.64
2014 | 5542 | 5.56 | 72.20
2015 | 5542 | 5.56 | 77.76
2016 | 5542 | 5.56 | 83.32
2017 | 5542 | 5.56 | 88.88
2018 | 5542 | 5.56 | 94.44
2019 | 5542 | 5.56 | 100.00
" %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint1_ours = `Freq.`)



check_point2_our <- 

"year | Freq. | Percent | Cum.
2003 | 3027 | 6.18 | 6.18
2004 | 3029 | 6.19 | 12.37
2005 | 3015 | 6.16 | 18.53
2006 | 3016 | 6.16 | 24.69
2007 | 3012 | 6.15 | 30.85
2008 | 3055 | 6.24 | 37.09
2009 | 3095 | 6.32 | 43.41
2010 | 3100 | 6.33 | 49.74
2011 | 3058 | 6.25 | 55.99
2012 | 3061 | 6.25 | 62.25
2013 | 3059 | 6.25 | 68.50
2014 | 3082 | 6.30 | 74.79
2015 | 3080 | 6.29 | 81.08
2016 | 3085 | 6.30 | 87.39
2017 | 3089 | 6.31 | 93.70
2018 | 3085 | 6.30 | 100.00
" %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint2_ours = `Freq.`)


check_point3_our <-  "
year | Freq. | Percent | Cum.
2003 | 3007 | 6.15 | 6.15
2004 | 3017 | 6.17 | 12.33
2005 | 3005 | 6.15 | 18.48
2006 | 3006 | 6.15 | 24.63
2007 | 3004 | 6.15 | 30.77
2008 | 3051 | 6.24 | 37.02
2009 | 3091 | 6.33 | 43.34
2010 | 3096 | 6.34 | 49.68
2011 | 3056 | 6.25 | 55.93
2012 | 3059 | 6.26 | 62.19
2013 | 3058 | 6.26 | 68.45
2014 | 3080 | 6.30 | 74.75
2015 | 3079 | 6.30 | 81.05
2016 | 3085 | 6.31 | 87.37
2017 | 3089 | 6.32 | 93.69
2018 | 3085 | 6.31 | 100.00
"  %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint3_ours = `Freq.`)


check_point4_our <-  "
year | Freq. | Percent | Cum.
2003 | 3007 | 6.15 | 6.15
2004 | 3017 | 6.17 | 12.33
2005 | 3005 | 6.15 | 18.48
2006 | 3006 | 6.15 | 24.63
2007 | 3004 | 6.15 | 30.77
2008 | 3051 | 6.24 | 37.02
2009 | 3091 | 6.33 | 43.34
2010 | 3096 | 6.34 | 49.68
2011 | 3056 | 6.25 | 55.93
2012 | 3059 | 6.26 | 62.19
2013 | 3058 | 6.26 | 68.45
2014 | 3080 | 6.30 | 74.75
2015 | 3079 | 6.30 | 81.05
2016 | 3085 | 6.31 | 87.37
2017 | 3089 | 6.32 | 93.69
2018 | 3085 | 6.31 | 100.00
"  %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint4_ours = `Freq.`)


# theirs -----

check_point1_their <- 
"year | Freq. | Percent | Cum.
1997 | 5505 | 5.51 | 5.51
1998 | 5505 | 5.51 | 11.02
1999 | 5507 | 5.51 | 16.53
2000 | 5507 | 5.51 | 22.05
2001 | 5560 | 5.57 | 27.61
2002 | 5560 | 5.57 | 33.18
2003 | 5559 | 5.56 | 38.74
2004 | 5559 | 5.56 | 44.31
2005 | 5563 | 5.57 | 49.87
2006 | 5563 | 5.57 | 55.44
2007 | 5563 | 5.57 | 61.01
2008 | 5563 | 5.57 | 66.58
2009 | 5564 | 5.57 | 72.15
2010 | 5564 | 5.57 | 77.72
2011 | 5564 | 5.57 | 83.29
2012 | 5564 | 5.57 | 88.86
2013 | 5566 | 5.57 | 94.43
2014 | 5566 | 5.57 | 100.00"  %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint1_theirs = `Freq.`)


check_point2_their <- "year | Freq. | Percent | Cum.
1999 | 2985 | 6.15 | 6.15
2000 | 2990 | 6.16 | 12.30
2001 | 2978 | 6.13 | 18.43
2002 | 3025 | 6.23 | 24.66
2003 | 3024 | 6.23 | 30.88
2004 | 3028 | 6.23 | 37.12
2005 | 3014 | 6.20 | 43.32
2006 | 3015 | 6.21 | 49.53
2007 | 3011 | 6.20 | 55.73
2008 | 3054 | 6.29 | 62.02
2009 | 3094 | 6.37 | 68.39
2010 | 3100 | 6.38 | 74.77
2011 | 3058 | 6.30 | 81.06
2012 | 3060 | 6.30 | 87.36
2013 | 3057 | 6.29 | 93.66
2014 | 3081 | 6.34 | 100.00"  %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint2_theirs = `Freq.`)

check_point3_their <- "
year  |  Freq. | Percent | Cum.
1999  |  2044 | 4.70 | 4.70
2000  |  2573 | 5.92 | 10.62
2001  |  2633 | 6.06 | 16.68
2002  |  2703 | 6.22 | 22.90
2003  |  2768 | 6.37 | 29.27
2004  |  2644 | 6.08 | 35.35
2005  |  2649 | 6.09 | 41.44
2006  |  2858 | 6.58 | 48.02
2007  |  2846 | 6.55 | 54.57
2008  |  2865 | 6.59 | 61.16
2009  |  2928 | 6.74 | 67.89
2010  |  2935 | 6.75 | 74.65
2011  |  2835 | 6.52 | 81.17
2012  |  2713 | 6.24 | 87.41
2013  |  2818 | 6.48 | 93.89
2014  |  2654 | 6.11 | 100.00
" %>% fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint3_theirs = `Freq.`)


check_point4_their <- "year | Freq. | Percent | Cum.
1999 | 2044 | 4.70 | 4.70
2000 | 2573 | 5.92 | 10.62
2001 | 2633 | 6.06 | 16.68
2002 | 2703 | 6.22 | 22.90
2003 | 2768 | 6.37 | 29.27
2004 | 2644 | 6.08 | 35.35
2005 | 2649 | 6.09 | 41.44
2006 | 2858 | 6.58 | 48.02
2007 | 2846 | 6.55 | 54.57
2008 | 2865 | 6.59 | 61.16
2009 | 2928 | 6.74 | 67.89
2010 | 2935 | 6.75 | 74.65
2011 | 2835 | 6.52 | 81.17
2012 | 2713 | 6.24 | 87.41
2013 | 2818 | 6.48 | 93.89
2014 | 2654 | 6.11 | 100.00"  %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint4_theirs = `Freq.`)


check_point3_alt_their <- 
"
year |      Freq. |Percent | Cum.
1999 |      2038 | 4.69 | 4.69
2000 |      2567 | 5.91 | 10.61
2001 |      2628 | 6.05 | 16.66
2002 |      2700 | 6.22 | 22.88
2003 |      2766 | 6.37 | 29.25
2004 |      2644 | 6.09 | 35.34
2005 |      2649 | 6.10 | 41.44
2006 |      2856 | 6.58 | 48.02
2007 |      2846 | 6.56 | 54.58
2008 |      2860 | 6.59 | 61.16
2009 |      2926 | 6.74 | 67.90
2010 |      2934 | 6.76 | 74.66
2011 |      2831 | 6.52 | 81.18
2012 |      2709 | 6.24 | 87.42
2013 |      2812 | 6.48 | 93.90
2014 |      2649 | 6.10 | 100.00
" %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint3_alt_theirs = `Freq.`)

check_point4_alt_their <- 
"
year |      Freq. | Percent | Cum.
1999 |      2038 | 4.69 | 4.69
2000 |      2567 | 5.91 | 10.61
2001 |      2628 | 6.05 | 16.66
2002 |      2700 | 6.22 | 22.88
2003 |      2766 | 6.37 | 29.25
2004 |      2644 | 6.09 | 35.34
2005 |      2649 | 6.10 | 41.44
2006 |      2856 | 6.58 | 48.02
2007 |      2846 | 6.56 | 54.58
2008 |      2860 | 6.59 | 61.16
2009 |      2926 | 6.74 | 67.90
2010 |      2934 | 6.76 | 74.66
2011 |      2831 | 6.52 | 81.18
2012 |      2709 | 6.24 | 87.42
2013 |      2812 | 6.48 | 93.90
2014 |      2649 | 6.10 |100.00
"  %>% 
  fread() %>% 
  .[, .(year, `Freq.`)] %>% 
  dplyr::rename( checkpoint4_alt_theirs = `Freq.`)
Code
check_point_ours <- merge(check_point1_our, check_point2_our, "year", all=T) %>% 
  merge(check_point3_our, "year", all=T) %>% 
  merge(check_point4_our, "year", all=T) 

check_point_theirs <- merge(check_point1_their, check_point2_their, "year", all=T) %>% 
  merge(check_point3_their, "year", all=T) %>% 
  merge(check_point4_their, "year", all=T) %>% 
  merge(check_point3_alt_their, "year", all=T) %>% 
  merge(check_point4_alt_their, "year", all=T) 


check_point_ours_long <-  melt.data.table(check_point_ours, id.vars = c("year"))
check_point_theirs_long <-  melt.data.table(check_point_theirs, id.vars = c("year"))


check_points <- rbind(check_point_ours_long,check_point_theirs_long)

5.3.1 Tabulating snapshots (tab year)

Code
check_point_ours %>%
  rename_columns(
    current_names = c('checkpoint1_ours', 'checkpoint2_ours', 'checkpoint3_ours', 'checkpoint4_ours'), 
    new_names = c("Snapshot 1", "Snapshot 2", "Snapshot 3", "Snapshot 4"))

tab year (Our data)

All of the output is based off of the tab year command in Stata. The goal is to have four snapshots of the data, first once all of the data is loaded, second when the first major set of filters is applied, third when observations are dropped if there is missing private employment and fourth, right before saving the data-set. We label these four snapshots “Snap-shot 1”, “Snap-shot 2”, “Snap-shot 3” and “Snap-shot 4”, respectively.

?(caption)

Code
check_point_theirs %>%
  rename_columns(
    current_names = c('checkpoint1_theirs', 'checkpoint2_theirs', 'checkpoint3_theirs', 'checkpoint4_theirs', 'checkpoint3_alt_theirs', 'checkpoint4_alt_theirs'), 
    new_names = c("Snapshot 1", "Snapshot 2", "Snapshot 3", "Snapshot 4", "Snapshot 3 Alt", "Snapshot 4 Alt"))

tab year (Their data)

All of the output is based off of the tab year command in Stata. The goal is to have four snapshots of the data, first once all of the data is loaded, second when the first major set of filters is applied, third when observations are dropped if there is missing private employment and fourth, right before saving the data-set. We label these four snapshots “Snap-shot 1”, “Snap-shot 2”, “Snap-shot 3” and “Snap-shot 4”, respectively. In the original paper, at snapshot 3, they drop observations where either public or private employment statistics are missing. We do not do this because we are only interested in creating statistics. Therefore, let “Snap-shot 3” and “Snap-shot 4” be snapshots of the original data while “Snap-shot 3 Alt” and “Snap-shot 4 Alt” refer to snapshots of the same lines when we only drop missing private employment.

?(caption)

5.3.2 Visualizing snapshots (tab year)

The Main Snap-shots figure illustrates that while at the first snapshot both data-sets have a similar number of observations, by snap-shot 4, they look exactly like the comparative statistics shown above (as expected). The Snapshot 1 figure illuatrates that there are some minor differences in the number of observations for the input data-sets. Snapshot 2 shows us that once the initial restrictions are applied, both data-sets are virutally identical in terms on numbers of observations. Since no observations are dropped between Snapshot 2 and the line of code which separates section Snapshot 3, it is pretty evident that this is where the differences in samples comes from, as the data-sets start taking on their final shapes. Snapshot 4 shows little to no difference from Snapshot 3.

In Snapshot 3, they drop all observations with missing public or private employment. Since we only require dropping missing private employment, we create figure Snapshot 3 - Alternate, which compares their data if they only drop missing private employment (like us) or drop both mossing public and private employment. The differences across data-sets is marginal. This leads us to question why they have so many missing labor market variables.

Code
check_points %>% 
  .[, Ours := stri_detect_fixed(variable, "ours")] %>% 
  .[, Snapshot := stri_extract_first_regex(variable, "\\d")] %>% 
  .[  !(!stri_detect_fixed(variable, "_alt_") & Snapshot > 3)] %>%
  ggplot(aes(x=year, y =value, color = Snapshot, linetype=Ours)) + 
  geom_point() + 
  geom_line() + 
  ylab("Number of Obs (municipality-years)")  + 
  theme_bw()

Code
check_points %>% 
  .[, Ours := stri_detect_fixed(variable, "ours")] %>% 
  .[, Snapshot := stri_extract_first_regex(variable, "\\d")] %>% 
  .[, Alternate := stri_detect_fixed(variable, "_alt_")] %>% 
  # drop alternate snapshot
  .[Snapshot==1] %>% 
  ggplot(aes(x=year, y =value, color = Snapshot, linetype = Ours)) + 
  geom_point() + 
  geom_line() + 
  xlab("Year") + 
  ylab("Number of Obs (municipality-years)")  + 
  theme_bw()

Code
check_points %>% 
  .[, Ours := stri_detect_fixed(variable, "ours")] %>% 
  .[, Snapshot := stri_extract_first_regex(variable, "\\d")] %>% 
  .[, Alternate := stri_detect_fixed(variable, "_alt_")] %>% 
  # drop alternate snapshot
  .[Snapshot==2] %>% 
  ggplot(aes(x=year, y =value, color = Snapshot, linetype = Ours)) + 
  geom_point() + 
  geom_line() + 
  xlab("Year") + 
  ylab("Number of Obs (municipality-years)")  + 
  theme_bw()

Code
check_points %>% 
  .[, Ours := stri_detect_fixed(variable, "ours")] %>% 
  .[, Snapshot := stri_extract_first_regex(variable, "\\d")] %>% 
  .[, Alternate := stri_detect_fixed(variable, "_alt_")] %>% 
  # drop alternate snapshot
  .[Snapshot==3] %>% 
  ggplot(aes(x=year, y =value, color = Alternate, linetype = Ours, label = value)) + 
  geom_point() + 
  geom_line() + 
  geom_label_repel(max.overlaps = 4)  +
  xlab("Year") + 
  ylab("Number of Obs (municipality-years)")  + 
  theme_bw()

Code
check_points %>% 
  .[, Ours := stri_detect_fixed(variable, "ours")] %>% 
  .[, Snapshot := stri_extract_first_regex(variable, "\\d")] %>% 
  .[, Alternate := stri_detect_fixed(variable, "_alt_")] %>% 
  # drop alternate snapshot
  .[Snapshot==4] %>% 
  ggplot(aes(x=year, y =value, color = Alternate, linetype = Ours, label = value)) + 
  geom_point() + 
  geom_line() + 
  geom_label_repel(max.overlaps = 4)  + 
  theme_bw()

Code
check_points %>% 
  .[, Ours := stri_detect_fixed(variable, "ours")] %>% 
  .[, Snapshot := stri_extract_first_regex(variable, "\\d")] %>% 
  .[, Alternate := stri_detect_fixed(variable, "_alt_")] %>%
  # drop alternate snapshot
  .[Ours==FALSE & Snapshot==3] %>% 
  ggplot(aes(x=year, y =value, color = Snapshot, linetype = Alternate)) + 
  geom_point() + 
  geom_line()  + 
  theme_bw()

5.4 Why do they have so many missing labor markets?

In this section, we try to understand possible reasons as to why this data is missing.

Since this discovery was made while looking at Snapshots 2 and 3, we start off by probing a version of each data-set, taken from the end of snapshot 2, right before we drop the observations which show up in Snapshot 3.

The first analysis we perform on this data-set is to merge both data-sets on municipality-year and only keep the observations where one data-set has missing private employment (prin). We focus on missing prin because missing public sector employment pubn has been shown to only marginally alter their data-set.

There is a clear difference in the quantity and quality of observations that they drop vs those which we drop. For starters, looking at
Drop missing (prin) in THEIR data, there are 2697 observations which they have missing labor market data for but which we have ample data for.

Secondly, looking at Drop missing (prin) in OUR data, there are only 80 observations and despite most of the observations that are missing in our data, are also missing in their data. When we drop those that are also missing in their data, we are left with only 7 unique municipalities present in their data but not in ours (See table Missing Private Employment Summary).

To test whether municipalities are not included because they have vrey few workers to begin with, we plot the distribution of private employment from our data for the municipalities where private employment is missing in theirs. As it turns out, two thirds of municipalities have less than 300 workers individuals, but this should be somewhat expected. What is alarming is that the distribution stretches far beyond this value. There is missing data for municipalities along the entire distribution private sector employment.

5.4.1 Looking at the data between Snapshot 2 and 3.

Code
# load data saved right before checkpoint 3 in THEIR data 
theirs_checkpointpre3 <- haven::read_dta(paste0(dir_transfers_replication, "data/processing/main_exact_data_checkpointpre3.dta")) %>% data.table()  %>% 
  .[, .(year, cod6, prin, prit, priw)] %>% 
  rename_columns(
    current_names = c("prin", "prit", "priw"), 
    new_names = c("prin_theirs", "prit_theirs", "priw_theirs") 
    )

# load data saved right before checkpoint 3 in OUR data 
ours_checkpointpre3 <- haven::read_dta(paste0(dir_transfers_replication, "data/processing/our_replication_data_for_figures_checkpointpre3.dta")) %>% data.table() %>% 
  .[, .(year, cod6, prin, prit, priw)] %>% 
  rename_columns(
    current_names = c("prin", "prit", "priw"), 
    new_names = c("prin_ours", "prit_ours", "priw_ours") 
    )

# merge both data-sets between 2003-2013
joint <- merge(theirs_checkpointpre3, ours_checkpointpre3, by =c("year", "cod6"), all=T) %>% 
  .[(year>=2003)&(year<=2013)] 

# see what happens when we impose the `Checkpoint 3` drop missing data constraint (ONLY ON PRIVATE)
joint_missing_in_theirs <-joint %>% copy() %>% 
  .[is.na(prin_theirs)]

# see what happens when we impose the `Checkpoint 3` drop missing data constraint (ONLY ON PRIVATE)
joint_missing_in_ours <- joint %>% copy() %>% 
  .[is.na(prin_ours)]
Code
joint_missing_in_theirs

Drop missing (prin) in THEIR data

Code
joint_missing_in_ours

Drop missing (prin) in OUR data

Code
joint_missing_in_theirs %>% 
  ggplot(aes(x=prin_ours)) + 
  geom_histogram(bins = 100)  + 
  theme_bw()

Distribution of Private Sector employment for missing observations in their data
Code
joint_missing_in_theirs_prin <-  joint_missing_in_theirs[, .N, prin_ours<300][, perc := 100*round(N/sum(N), 3)]
joint_missing_in_theirs_prin %>% 
  rename_columns(current_names = c("prin_ours", "N", "perc"), new_names = c("Private Employment < 300", "Count", "%") ) 
Code
joint_missing_in_ours %>% 
  ggplot(aes(x=prin_theirs)) + 
  geom_histogram(bins = 100)  + 
  theme_bw()

Code
missing_in_theirs_1 <-  joint_missing_in_theirs[, uniqueN(cod6)]
missing_in_ours_1 <-   joint_missing_in_ours[, uniqueN(cod6)]

missing_in_theirs_2 <-   joint_missing_in_theirs[!is.na(prin_ours)][, uniqueN(cod6)]
missing_in_ours_2 <-   joint_missing_in_ours[!is.na(prin_theirs)][, uniqueN(cod6)]

data.table(
  Description = c(
  "Unique Municipalities missing in Theirs",
  "Unique Municipalities missing in Theirs, not missing in ours",
  "Unique Municipalities missing in Ours", 
  "Unique Municipalities missing in Ours, not missin in theirs"), 
  Value = c(missing_in_theirs_1, missing_in_theirs_2, missing_in_ours_1, missing_in_ours_2))

Descriptive statistics about missing prin in both data-sets

5.4.2 Looking at Snapshot 1 data

Code
ours_input <- "our_replication_data.dta" %>% 
  paste0(dir_transfers_replication, "data/", .) %>% 
  haven::read_dta() %>% 
  as.data.table()   %>% 
    .[, .(year, cod6, prin)]  %>% 
  .[, Ours := TRUE]

theirs_input <- "main_exact_data_checkpointpre1.dta" %>% 
  paste0(dir_transfers_replication, "data/processing/", .) %>% 
  haven::read_dta() %>% 
  as.data.table()   %>% 
    .[, .(year, cod6, prin,prin_b10_1)] %>% 
  rename(., prin_theirs = prin) %>% 
  .[, Theirs := TRUE]

both_input <- merge(ours_input, theirs_input, by = c("cod6", "year"), all=T) %>% 
  .[, Both := Ours*Theirs] %>% 
  .[year<2015&year>2001]

both_input_nomiss <- merge(ours_input[!is.na(prin)], theirs_input[!is.na(prin_theirs)], by = c("cod6", "year"), all=T) %>% 
  .[, Both := Ours*Theirs] %>% 
  .[year<2015&year>2001]

5.4.2.1 At Snapshot 1, how different are the data-sets?

Figure 5.1 presents the number of observations in the input data-sets. Both data-sets are very similar in terms of number of observations. For the majority of the sample period (2002-2014), our municipality-years are completely contained within theirs. Despite this initial similarity in data-set size, in Figure 5.2 we observe that thei data-set has roughly 1500 less than ours when we remove missing prin from both data-sets.

Code
both_input %>% copy() %>% 
  .[, Theirs_yearly := sum(Theirs, na.rm=T), year] %>% 
  .[, Ours_yearly := sum(Ours, na.rm=T), year] %>% 
  .[, Both_yearly := sum(Both, na.rm=T), year] %>% 
  .[!duplicated(year), .(year, Theirs_yearly, Ours_yearly, Both_yearly)] %>% 
  rename_columns(
    current_names = c("Theirs_yearly", "Ours_yearly", "Both_yearly"),
    new_names = c("Their data", "Our data", "In Common")) %>% 
  melt.data.table(id.vars = c("year")) %>% 
  ggplot(aes(x=year, y=value, color=variable, linetype=variable)) + 
  geom_point() + 
  geom_line() + 
  ylab("Observations (Municipality-Years)") + 
  xlab("Year") + 
  labs(color="", linetype="") + 
  theme_bw()

(a) This figure presents the number of observations (municipality-years) in each data-set between 2002-2014 once all of the data is loaded in at Snapshot 1. Here, we see that they have roughly 30 more observations than we do at the start. Their/Our data refers to the municipality years in their/our data-sets. In Common referes to the municipality-years both data-sets share.
Figure 5.1: Snapshot 1) Observations common to both data-sets.
Code
both_input_nomiss %>% copy() %>% 
  .[, Theirs_yearly := sum(Theirs, na.rm=T), year] %>% 
  .[, Ours_yearly := sum(Ours, na.rm=T), year] %>% 
  .[, Both_yearly := sum(Both, na.rm=T), year] %>% 
  .[!duplicated(year), .(year, Theirs_yearly, Ours_yearly, Both_yearly)] %>% 
  rename_columns(
    current_names = c("Theirs_yearly", "Ours_yearly", "Both_yearly"),
    new_names = c("Their data", "Our data", "In Common")) %>% 
  melt.data.table(id.vars = c("year")) %>% 
  ggplot(aes(x=year, y=value, color=variable, linetype=variable)) + 
  geom_point() + 
  geom_line() + 
  ylab("Observations (Municipality-Years)") + 
  xlab("Year") + 
  labs(color="", linetype="") + 
  theme_bw()

(a) This figure presents the number of observations (municipality-years) in each data-set between 2002-2014 once all of the data is loaded in at Snapshot 1 and observations with missing private employment (prin) are dropped. Here, we see that our data has roughly 1500 more observations theirs at the start. Their/Our data refers to the municipality years in their/our data-sets. In Common referes to the municipality-years with non-missing prin in both data-sets.
Figure 5.2: Snapshot 1) Observations common to both data-sets without missing Privae Employment.

5.4.2.2 Inputs to Snapshot 1

Code
RAIS_sectors <- haven::read_dta(paste0(dir_transfers_replication, "data/RAIS_sectors.dta")) %>% as.data.table() 
RAIS_2digit <- haven::read_dta(paste0(dir_transfers_replication, "data/RAIS_2digit.dta")) %>% as.data.table()

# number of observations

# nrow
RAIS_sectors %>% .[, .N, .(year, cod6)] %>% .[N>1]
Code
RAIS_2digit %>% .[, .N, .(year, cod6)] %>% .[N>1]
Code
# nrow
RAIS_sectors_nrow <- RAIS_sectors %>% nrow()
RAIS_2digit_nrow <- RAIS_2digit %>% nrow()

# missing prin
RAIS_sectors_reduced <- RAIS_sectors %>% .[, .(cod6, year, prin, prin_b10)] %>% .[, Sectors := TRUE] %>% 
  rename(., prin_sectors = prin)
RAIS_2digit_reduced <- RAIS_2digit %>% .[, .(cod6, year, prin, prin_b10_1)] %>% .[, Digit2 := TRUE] %>% 
    rename(., prin_2digit = prin)

joint_RAIS <- merge(RAIS_sectors_reduced, RAIS_2digit_reduced, by = c("year", "cod6"), all=T) %>% 
  .[, Both := Sectors*Digit2]

# joint_RAIS %>% 
#   .[Sectors==TRUE] %>% 
#   .[, .N, .(is.na(prin_sectors), is.na(prin_b10))]
# 
# 
# joint_RAIS %>% 
#   .[, .N, .(prin_sectors_missing=is.na(prin_sectors),prin_2digit_missing=is.na(prin_2digit), prin_b10_missing=is.na(prin_b10), prin_b10_1_missing=is.na(prin_b10_1),  either_missing=is.na(Both))]
# 
# 
5.4.2.2.1 Comparing RAIS_sectors with RAIS_2digit

In the first section of the cleaning file, the authors merge in two data-sets: RAIS_sectors.dta then RAIS_2digit.dta. In Table 5.1 and Table 5.2 we merge the two data-sets by municipality-year and show the number of missing observations present for each set of variables. Table 5.1 shows the number of missing observations for each data-set’s version of the prin variable and concludes that both data-sets have a very large number of missing prin, though RAIS_2digit.dta has 546 or so more. Meanwhile, Table 5.2 compares missing data for the prin_b10 and prin_b10_1 variables and highlights that the prin_b10 variable (and all other RAIS_sector variables) have consideraby more missing data.

Code
joint_RAIS %>% 
  .[, .N, .(prin_sectors_missing=is.na(prin_sectors),prin_2digit_missing=is.na(prin_2digit))] %>% 
  rename_columns(
    current_names = c("prin_sectors_missing", "prin_2digit_missing", "N"),
    new_names = c("Missing prin (RAIS_sectors)", "Missing prin (RAIS_2digit)", "Count") )
Table 5.1:

Comparing missing prin for RAIS_sector and RAIS_2digit input data-sets

Code
joint_RAIS %>% 
  .[, .N, .(prin_b10_missing=is.na(prin_b10), prin_b10_1_missing=is.na(prin_b10_1))] %>% 
    rename_columns(
    current_names = c("prin_b10_missing", "prin_b10_1_missing", "N"),
    new_names = c("Missing prin_b10 (RAIS_sectors)", "Missing prin_b10_1 (RAIS_2digit)", "Count") )
Table 5.2:

Comparing missing prin’s for RAIS_sector and RAIS_2digit input data-sets

5.4.3 Looking at Snapshot 4 data

5.4.4 At Snapshot 4, how different are the data-sets?

Code
ours_output <- "our_replication_data.dta" %>% 
  paste0(dir_transfers_replication, "data/", .) %>% 
  haven::read_dta() %>% 
  as.data.table()   %>% 
    .[, .(year, cod6, prin, popibge)]  %>% 
    rename(., popibge_ours = popibge) %>% 
  .[, Ours := TRUE]

theirs_output <- "main_exact_data.dta" %>% 
  paste0(dir_transfers_replication, "data/processing/", .) %>% 
  haven::read_dta(col_select = c("year", "cod6","popibge", "prin", "prin_b10_1")) %>% 
  as.data.table()   %>% 
    .[, .(year, cod6, prin,prin_b10_1, popibge)] %>% 
  rename(., prin_theirs = prin) %>% 
  rename(., popibge_theirs = popibge) %>% 
  .[, Theirs := TRUE]

both_output <- merge(ours_output, theirs_output, by = c("cod6", "year"), all=T) %>% 
  .[, Both := Ours*Theirs] %>% 
  .[year<2015&year>2001]

both_output_nomiss <- merge(ours_output[!is.na(prin)], theirs_output[!is.na(prin_theirs)], by = c("cod6", "year"), all=T) %>% 
  .[, Both := Ours*Theirs] %>% 
  .[year<2015&year>2001]
Code
both_output %>%
  .[, in_sample_ours := (popibge_ours>6793 &  popibge_ours<47537)] %>% 
  .[, .N, .(is.na(prin_theirs), in_sample_ours)] %>%
    .[, perc := round(100*(N/sum(N)), digits = 2)] %>% 
  ggplot(aes(x=in_sample_ours, y = `is.na`, fill=N, label=paste0(perc, "%"))) + 
  geom_tile() + 
  geom_text() + 
  scale_fill_fermenter(palette = "Greens", direction = 1) + 
  xlab("Population below between 6,793 and 47,537") + 
  ylab("Is prin missing?")  + 
  labs(fill="Mun-Year") + 
  theme_bw()

Figure 5.3: Missing Prin and Sample Restrictions - Their data
Code
both_output %>%
  .[, in_sample_ours := (popibge_ours>6793 &  popibge_ours<47537)] %>% 
  .[, .N, .(is.na(prin), in_sample_ours)] %>%
    .[, perc := round(100*(N/sum(N)), digits = 2)] %>% 
  ggplot(aes(x=in_sample_ours, y = `is.na`, fill=N, label=paste0(perc, "%"))) + 
  geom_tile() + 
  geom_text() + 
  scale_fill_fermenter(palette = "Greens", direction = 1) + 
  xlab("Population below between 6,793 and 47,537") + 
  ylab("Is prin missing?")  + 
  labs(fill="Mun-Year") + 
  theme_bw()

Figure 5.4: Missing Prin and Sample Restrictions - Our data
Code
# load in population cut-offs
population_thresholds <- 
  paste0(dir_fpm, "fpm_variables/fpm_lambda_coeff_min_popest.csv") %>%
  fread() %>% 
  .[, cutoff_upper := min_popest + 1500] %>% 
  .[, cutoff_lower := min_popest - 1500]  

# add the population cut-offs to the data
for(i in 1:nrow(population_thresholds)){
      
      # message_with_lines(i)
      
      POP_CUTOFF <- population_thresholds[i, min_popest]
      POP_CUTOFF_max <- population_thresholds[i+1, min_popest]

      both_output[popibge_ours>=POP_CUTOFF, population_cutoff_min := POP_CUTOFF]
      both_output[popibge_ours>=POP_CUTOFF, population_cutoff_max := POP_CUTOFF_max]
      
}


# determine whether the observation falls within the 1500 margin 
both_output %<>% 
  .[, within_margin_lower := (abs(popibge_ours-population_cutoff_min)<=1500)] %>% 
  .[, within_margin_upper := (abs(population_cutoff_max-popibge_ours)<=1500)] %>% 
  .[, within_margin := within_margin_upper==TRUE | within_margin_lower==TRUE ]  %>% 
  .[, within_margin := within_margin ==TRUE & in_sample_ours==TRUE ]   
Code
both_output %>%
  .[, in_sample_and_margin_ours := in_sample_ours ==T & within_margin==TRUE] %>% 
  .[, .N, .(is.na(prin_theirs), in_sample_and_margin_ours)] %>%
    .[, perc := round(100*(N/sum(N)), digits = 2)] %>% 
  ggplot(aes(x=in_sample_and_margin_ours, y = `is.na`, fill=N, label=paste0(perc, "%"))) + 
  geom_tile() + 
  geom_text() + 
  scale_fill_fermenter(palette = "Greens", direction = 1) + 
  xlab("Population below between 6,793 - 47,537 & within 1500 of a cut-off") + 
  ylab("Is prin missing?")  + 
  labs(fill="Mun-Year") + 
  theme_bw()

Figure 5.5: Missing Prin and Sample Restrictions with Margins - Their data
Code
both_output %>%
  .[, in_sample_and_margin_ours := in_sample_ours ==T & within_margin==TRUE] %>% 
  .[, .N, .(is.na(prin), in_sample_and_margin_ours)] %>%
    .[, perc := round(100*(N/sum(N)), digits = 2)] %>% 
  ggplot(aes(x=in_sample_and_margin_ours, y = `is.na`, fill=N, label=paste0(perc, "%"))) + 
  geom_tile() + 
  geom_text() + 
  scale_fill_fermenter(palette = "Greens", direction = 1) + 
  xlab("Population below between 6,793 - 47,537 & within 1500 of a cut-off") + 
  ylab("Is prin missing?")  + 
  labs(fill="Mun-Year") + 
  theme_bw()

Figure 5.6: Missing Prin and Sample Restrictions with margins - Our data