Summary

This code calculates averages of the event study estimates from the Swedish couples project using traditional TWFE cohort-specific regressions. This is an attempt to manually reproduce the results found using Borusyak, Jaravel, and Speiss’ (2022) did_imputation package. In the end, I plot the traditional TWFE estimates, and the manual TWFE averages against the did_imputation Stata output used with the options horizons and hbalance, as well as the year and child effects by cohort.

What I do:

  1. Import regression outputs from log files
  2. Define BJS’s weights for each cohort for each event period
  3. Calculate averages for different time intervals
  4. Plot results for different time intervals
  5. Plot year fixed efects by cohort
  6. Plot child effects by cohort

Results from log file

To import the results from the log file, I execute the following steps:

  1. Identify in which line of the log file each regression output starts;
  2. Import the cohort-gender-specific results separately;
  3. Merge these different tables, and organize the data.

The only manual manual step here is to identify where each regression output starts in the log file.

# R setup
library(tidyverse)
library(readr)
library(kableExtra)
rm(list = ls())
setwd("C:/Users/amarino0/Documents/swedish_couples/code")

Cohort-specific TWFE

Import results for each cohort-gender

# Vectors of line skips, years, and gender
line_skips <- c(318,398,561,641,804,885,1049,1130,1293,1376,1539,1623,1786,1871,
                2034,2122,2285,2373,2537,2626,2790,2880,3044,3135,3290,3382)
  #-- Note: this is manually observed in the log file and then typed here
  #-- this part will always have to be, at least partially, "hand-made", since 
  #-- only humans know what they want from the log-file
years <- rep(1995:2007,2) %>% sort()
genders <- rep(c("men","women"),length(line_skips)/2)

# Function to import regression output
import_reg_output <- function(year, line_skip, gender) {
  reg_output <- 
    read.table("../logs/analyze_mainfigures_bycohort.log", # read reg output
             skip = line_skip, nrows = 46, header = FALSE, fill = TRUE) %>%
    as.data.frame() %>% # transform in data frame
    select(V1,V3) %>% # keep only labels and point estimates
    setNames(c("labels",paste0(year,"_",gender))) # change names to year_gender
  return(reg_output) # output of the function is a dataset with the regression results
}

# Apply function to all cohorts
for (i in 1:length(line_skips)) {
  assign(paste0("estimates_",years[i],"_",genders[i]), # saves each output in one dataset
         import_reg_output(year=years[i],line_skip=line_skips[i],gender=genders[i]))
}

rm(list = c("line_skips","years","genders")) # remove vectors

Merge results

# Merge all regression outputs
point_estimates <- 
  lapply(ls(pattern = "^estimates"), get) %>% # create list with all datasets
  reduce(left_join, by = "labels") # merge all by coefficient label

# Identify NAs
which(is.na(point_estimates), arr.ind=TRUE, useNames=TRUE)
##      row col
## [1,]   1   8
## [2,]   1  17
  #--- For some reason, two point estimates were not properly imported
  #--- I will have to input them manually, although that is not ideal. 
point_estimates[1,8] <- -3.303374
point_estimates[1,17] <- -1.199227

rm(list = ls(pattern="^estimates")) # delete cohort-specific dataframes

# Print sample dataset
kable(point_estimates) %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "100%", height = "150px")
labels 1995_men 1995_women 1996_men 1996_women 1997_men 1997_women 1998_men 1998_women 1999_men 1999_women 2000_men 2000_women 2001_men 2001_women 2002_men 2002_women 2003_men 2003_women 2004_men 2004_women 2005_men 2005_women 2006_men 2006_women 2007_men 2007_women
_Ieventmove_m5 -2.6405290 -0.9536016 -3.0547720 -1.2564440 -3.2367920 -1.3405180 -3.3033740 -1.4236160 -3.1182050 -1.3234620 -3.3157200 -1.4159610 -3.1920280 -1.4029360 -3.2286910 -1.1992270 -3.0711700 -1.2993800 -3.2810690 -1.3409240 -3.2383980 -1.3476040 -3.1401950 -1.2652420 -3.0801470 -1.1713800
_Ieventmove_m4 -1.0233770 0.1850816 -1.3419440 -0.0501307 -1.4900410 -0.1183245 -1.5408470 -0.1799799 -1.3961850 -0.1075824 -1.5614450 -0.1874839 -1.4569120 -0.1718986 -1.4834620 -0.0078704 -1.3564700 -0.0851668 -1.5249840 -0.1176510 -1.4739690 -0.1169517 -1.4018230 -0.0487248 -1.3505460 0.0262928
_Ieventmove_m3 -1.8370580 0.0274307 -2.0536960 -0.1330074 -2.1610960 -0.1851506 -2.1962910 -0.2291071 -2.1025680 -0.1789874 -2.2212280 -0.2407434 -2.1300140 -0.2218565 -2.1522940 -0.1032168 -2.0491850 -0.1546298 -2.1735190 -0.1767365 -2.1340570 -0.1777445 -2.0824110 -0.1227247 -2.0422680 -0.0664935
_Ieventmove_m2 -5.5399490 -2.0223380 -5.6825590 -2.1256250 -5.7489870 -2.1697920 -5.7762220 -2.2017920 -5.7228670 -2.1713250 -5.7981050 -2.2062160 -5.7283810 -2.1873630 -5.7471200 -2.1082160 -5.6738950 -2.1425900 -5.7572670 -2.1596600 -5.7345210 -2.1616760 -5.6981290 -2.1184510 -5.6699420 -2.0803850
_Ieventmove_m1 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p0 24.8931400 0.1993835 -1.8857990 -14.1422000 6.0962630 -15.4156900 5.5003680 -7.7877850 11.3229900 -2.5627390 17.7739800 6.7720640 7.8582930 1.1922030 0.0657903 -7.5992820 -2.8334720 -14.2294800 -5.1726290 -15.5960200 -2.9707380 -10.5259400 1.3055260 -6.8831950 0.0000000 0.0000000
_Ieventmove_p1 19.8739200 -3.1004090 -3.1476310 -20.3272300 4.9317280 -12.6198700 8.5736750 -4.8558660 12.4572900 2.6309060 12.4585700 6.7668650 6.1270820 2.3254960 -4.2659360 -7.6805820 -10.3148200 -18.7497700 -12.7170300 -17.0718500 -7.0109610 -8.5420700 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p2 23.0116600 -2.8282450 0.7581085 -17.6789100 10.9912900 -6.3550040 20.4898500 3.3000660 15.3663200 7.2364410 18.4137200 10.3619000 13.5551800 6.4280400 1.4672100 -5.1534050 -7.9866050 -15.6204800 -5.7872640 -10.1937000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p3 24.6096300 -4.6091610 9.7881370 -10.1881800 21.0580200 0.2417271 21.2249200 8.6929660 23.0699400 10.6485600 21.1658000 14.4078100 15.9334100 9.5815770 -0.4709103 -3.1676030 -5.8191010 -8.0720880 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p4 30.1655600 1.8195590 19.0273700 -4.1655000 23.9392900 2.7884010 28.1485200 13.0479400 28.4260700 14.3011500 27.6402400 17.2068200 21.5163800 11.3781500 6.2674000 1.5577550 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p5 35.7872600 5.0001990 20.2699400 1.1430280 33.8376000 10.8456400 33.5186100 16.0232900 34.9074000 17.3465600 30.4168400 22.3995400 25.3106100 14.6411100 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p6 38.3401900 9.9497920 29.8907100 6.8378940 42.4767800 16.9240600 39.0176700 21.9677100 37.9561800 21.5936200 34.6715700 26.9880600 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p7 47.5259100 14.9445400 37.0466900 13.9517200 48.0229900 19.7986700 41.6679900 25.9870700 42.0932900 28.8936300 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p8 51.3744400 19.5160500 45.3357300 20.6535700 48.4520900 23.5712500 47.4071900 31.1533000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p9 57.0553400 25.5588200 50.4536800 24.2198200 51.1574800 28.0880800 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventmove_p10 62.8946000 31.7474100 53.5585100 31.6857100 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Iyear_1991 -6.8979510 -2.9701770 -6.8960010 -2.9672740 -6.8913210 -2.9556230 -6.8976210 -2.9475610 -6.8806700 -2.9443510 -6.8765690 -2.9477680 -6.8968050 -2.9564630 -6.8994460 -2.9665510 -6.8917480 -2.9512950 -6.8814020 -2.9486680 -6.8918680 -2.9543150 -6.9174730 -2.9687210 -6.9140080 -2.9792880
_Iyear_1992 -10.8422700 -3.6079550 -10.8569700 -3.6196620 -10.8614900 -3.6147640 -10.8767300 -3.6148320 -10.8393500 -3.6011710 -10.8323600 -3.5961110 -10.8549700 -3.6092630 -10.8705200 -3.6204800 -10.8417200 -3.6010220 -10.8386900 -3.6029730 -10.8800100 -3.6177080 -10.9031400 -3.6372810 -10.9071200 -3.6470680
_Iyear_1993 -19.4468600 -7.7748050 -19.4735300 -7.7947920 -19.4698200 -7.7886550 -19.4912500 -7.7861320 -19.4442200 -7.7718800 -19.4436800 -7.7679070 -19.4826600 -7.7883000 -19.4890800 -7.7988720 -19.4730900 -7.7830660 -19.4664100 -7.7879420 -19.5068700 -7.8004890 -19.5376000 -7.8234680 -19.5400400 -7.8365280
_Iyear_1994 -23.1260300 -9.2098050 -23.0761500 -9.1853630 -23.0489000 -9.1675780 -23.0549500 -9.1594930 -23.0437200 -9.1714800 -23.0468600 -9.1720350 -23.0978700 -9.1911890 -23.0696600 -9.2225000 -23.1224900 -9.2104000 -23.0887900 -9.2103110 -23.1106800 -9.2104440 -23.1436700 -9.2395910 -23.1497000 -9.2548620
_Iyear_1995 -22.0112400 -7.7172890 -21.9596000 -7.6903070 -21.9392500 -7.6811240 -21.9500700 -7.6783830 -21.9299600 -7.6978420 -21.9538200 -7.7015320 -21.9872600 -7.7178330 -21.9677400 -7.7496160 -22.0162000 -7.7363420 -21.9887000 -7.7324830 -22.0171200 -7.7361620 -22.0415100 -7.7611740 -22.0431400 -7.7721050
_Iyear_1996 -6.2684480 3.3707030 -6.2365960 3.3793260 -6.2247010 3.3793820 -6.2429590 3.3741510 -6.2153710 3.3566470 -6.2566180 3.3479370 -6.2819430 3.3297370 -6.2586120 3.3118280 -6.3194200 3.3153560 -6.2966930 3.3126680 -6.3178970 3.3158710 -6.3363550 3.2929770 -6.3369420 3.2886340
_Iyear_1997 6.9158520 12.8659100 6.9288340 12.8575800 6.9252400 12.8597400 6.9039270 12.8494200 6.9400280 12.8278700 6.8735740 12.8061100 6.8674940 12.7910800 6.8844580 12.7794000 6.8356820 12.7797000 6.8446470 12.7837800 6.8372200 12.7838200 6.8281890 12.7669400 6.8309270 12.7674500
_Iyear_1998 21.9898200 24.0215200 21.9683000 23.9881600 21.9243300 23.9681800 21.8867300 23.9521400 21.9509300 23.9296200 21.8527000 23.9014000 21.8907000 23.8846000 21.8718700 23.8955400 21.8558400 23.8951700 21.8478500 23.9008100 21.8444200 23.9056600 21.8519100 23.8924100 21.8597300 23.9013800
_Iyear_1999 31.7845200 31.9536400 31.6957900 31.8746400 31.6204200 31.8458000 31.5763600 31.8156500 31.6655200 31.8151500 31.5541800 31.7788500 31.6166700 31.7672800 31.5781500 31.8052800 31.6104000 31.7972200 31.5677500 31.7993600 31.5615200 31.7954300 31.5859900 31.7948300 31.5986600 31.8165800
_Iyear_2000 43.9081000 37.0782500 43.7463700 36.9535300 43.6425500 36.9126000 43.5862600 36.8751300 43.7064000 36.8972700 43.5921400 36.8601900 43.6656000 36.8512600 43.6033900 36.9164600 43.6899500 36.9036400 43.6171500 36.9000600 43.6042900 36.8880200 43.6338800 36.8964900 43.6557700 36.9244400
_Iyear_2001 53.4138800 42.7587500 53.1631100 42.5688800 53.0282400 42.5229400 52.9629400 42.4769100 53.1154500 42.5290300 52.9912700 42.4836600 53.0701800 42.4700200 52.9972100 42.5690400 53.1302400 42.5372600 53.0184300 42.5273200 53.0045500 42.5085900 53.0533700 42.5279900 53.0763800 42.5668600
_Iyear_2002 48.8931300 43.1532800 48.6006000 42.9447300 48.4568800 42.8947500 48.3910600 42.8488200 48.5542200 42.9154600 48.4369200 42.8712900 48.5205500 42.8611100 48.4345500 42.9754600 48.5999800 42.9416000 48.4725200 42.9296900 48.4611100 42.9073100 48.5125000 42.9354500 48.5430300 42.9768200
_Iyear_2003 44.1896500 42.2868900 43.8365700 42.0353200 43.6772900 41.9905000 43.6105300 41.9471900 43.7950800 42.0415000 43.6894600 41.9947200 43.7549200 41.9765000 43.6682700 42.1125500 43.8656100 42.0659600 43.7156900 42.0483400 43.7031400 42.0223200 43.7589900 42.0526700 43.7890400 42.0963800
_Iyear_2004 44.7657700 45.1427400 44.3402600 44.8423900 44.1778000 44.8019200 44.1016900 44.7649600 44.3258900 44.8861900 44.2215300 44.8368000 44.2528400 44.8071800 44.1696800 44.9587300 44.4068700 44.9041500 44.2317300 44.8786700 44.2106300 44.8446100 44.2571900 44.8769400 44.2882700 44.9177800
_Iyear_2005 54.1408500 50.2463500 53.6828100 49.9251600 53.5236400 49.8887900 53.4427300 49.8521500 53.6757300 49.9946500 53.5929700 49.9482800 53.6055800 49.9183200 53.5223900 50.0753100 53.7898600 50.0231800 53.6052400 49.9907100 53.5694700 49.9463000 53.6024400 49.9789700 53.6348500 50.0164800
_Iyear_2006 62.7248300 55.6133100 62.2475500 55.2743400 62.0943900 55.2406800 62.0083900 55.2017100 62.2370400 55.3559900 62.1692400 55.3121700 62.1735900 55.2838000 62.0938900 55.4424100 62.3790600 55.3893000 62.1883700 55.3512200 62.1458300 55.2997400 62.1727700 55.3352200 62.2002700 55.3706700
_Ieventchild1_m1 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
_Ieventchild1_p0 -0.5923005 -97.1406400 -0.1700363 -97.0645500 -0.1090655 -97.3305000 -0.0178011 -98.0626000 -0.2509549 -97.8304000 -0.6570975 -98.1709700 -0.2124354 -97.7252100 0.4484474 -97.4829400 -0.2989136 -97.4421700 -0.3966057 -97.9393200 -0.4663523 -97.8290000 -0.6621057 -97.6976000 -0.6122537 -97.2215200
_Ieventchild1_p1 -9.3640520 -126.8718000 -8.9130350 -126.5645000 -9.0446180 -127.1517000 -9.2889180 -127.7079000 -9.3863930 -128.3320000 -10.4182300 -128.5958000 -9.7594190 -127.7724000 -9.4904770 -127.6339000 -9.9400900 -127.6030000 -10.2036800 -127.7147000 -9.8886610 -127.7699000 -10.1920800 -127.3419000 -9.4298050 -127.0538000
_Ieventchild1_p2 5.9328220 -84.7395600 6.7253170 -84.5257500 5.7893330 -84.6779400 6.0726770 -85.1028300 5.4087950 -85.4822000 4.7311110 -85.7758800 6.1248910 -85.7090900 5.9555740 -85.4507900 5.1774680 -86.1617600 4.8890000 -85.7081100 4.8385960 -85.7441300 6.5537710 -85.5002000 6.5581350 -84.9390800
_Ieventchild1_p3 11.8227200 -89.8365400 12.1149500 -89.1878300 11.9162300 -90.1037400 12.0677500 -90.2846100 11.8118200 -91.2412200 10.2422700 -91.2543800 12.0804100 -91.0490000 11.6169600 -90.6913300 10.5568100 -91.1448900 10.5148700 -90.9325600 11.5699900 -90.2441900 12.9267600 -89.5974800 13.0750300 -89.1172500
_Ieventchild1_p4 15.5214000 -76.8606600 16.2637300 -76.2429100 14.8409700 -76.5171000 14.8871700 -76.6803600 14.8466300 -77.3330400 13.2254600 -78.3178700 15.8797900 -78.2887200 14.8246100 -77.5743800 13.9700700 -77.1351000 14.5820200 -76.8044700 16.4178100 -75.8065100 16.6641400 -76.0637000 17.0501300 -75.6556100
_Ieventchild1_p5 19.9846700 -63.0204900 20.6212300 -63.0349600 18.8716900 -63.7580700 18.5641700 -63.2178100 19.1401300 -64.0392100 17.5417100 -64.8052200 19.8131400 -64.4926900 18.5028000 -63.9858300 20.7030000 -63.5514100 19.8713800 -63.1691600 21.1231000 -62.7081100 21.3470700 -62.3822300 21.4540500 -62.2086500
_Ieventchild1_p6 21.2363700 -58.3818000 20.0631200 -58.5904100 19.8848300 -59.7176100 18.9290800 -60.1782800 18.3185100 -60.2846400 18.1684000 -60.1386100 21.5356900 -58.9846500 19.1561500 -58.8503200 22.9827400 -57.8534700 22.1609600 -57.6235600 21.7793700 -58.5148400 21.9318400 -57.3060400 22.3134200 -57.2215500
_Ieventchild1_p7 21.6626700 -54.2779500 21.1341100 -54.9219800 19.1704200 -56.1027500 18.8183200 -57.9727100 16.9185700 -57.3329300 18.8364800 -56.3597500 22.4531700 -54.8649100 19.9899300 -54.0690000 22.2107300 -53.5662300 21.8938200 -53.9653700 21.0227900 -54.4691600 22.0234200 -54.0321200 21.6945200 -53.3623700
_Ieventchild1_p8 21.8248500 -50.3698300 20.6148500 -50.5943600 18.3280400 -50.5400500 19.7099200 -52.4532700 20.2622300 -51.1383100 21.3845400 -50.7545500 22.7020300 -49.0394300 21.2564600 -48.5304200 23.8210500 -47.9322700 22.0561800 -47.9354700 20.7297200 -49.1275900 21.6755400 -48.6730500 22.1337200 -47.5949000
_Ieventchild1_p9 21.6767700 -47.9399900 19.4700300 -48.1760300 18.2179600 -49.6758900 17.8650900 -49.7354100 19.6710400 -47.9399000 20.6600500 -47.4814400 21.2317000 -47.7879700 19.5758100 -45.9252800 21.1729000 -45.5783700 20.9203800 -46.4536700 19.4216200 -46.0873800 19.1171100 -46.2895300 20.1863800 -45.8461100
_Ieventchild1_p10 15.1293100 -40.9909400 8.7157550 -45.7481700 8.0757940 -45.5344700 7.4309050 -45.7695400 10.0584000 -43.5863700 9.2268330 -44.3688900 6.9791590 -45.0022100 8.2739740 -42.9575800 9.9651600 -44.7466600 7.3823730 -45.5304100 7.3615960 -46.0304100 7.6325160 -45.3613700 7.9887540 -44.9081700
no_child1 -31.6712900 -36.0426700 -29.9893700 -34.6583200 -28.8315100 -34.4838800 -27.7462000 -34.3051100 -29.9371000 -34.5589800 -29.3078300 -34.8081500 -29.3827000 -34.0248900 -27.7489100 -33.8898300 -29.3377400 -34.5442700 -29.2496100 -34.6476800 -27.9250500 -34.2460000 -27.6554500 -33.4009600 -27.2410400 -33.0701800
_cons 234.2066000 173.3460000 234.9550000 173.8601000 235.2848000 174.0929000 235.2609000 174.3562000 235.1985000 174.1294000 235.5872000 174.4092000 235.1641000 174.1552000 235.0212000 173.5820000 234.8354000 173.9223000 235.3949000 174.0637000 235.0934000 174.0394000 234.7871000 173.6516000 234.5235000 173.3096000

Treatment effects dataset

To facilitate the use of the dataset, I separate it only for treatment effect coefficients, and reshape it.

# Treatment effects coefficients
treatment_effects <- 
  point_estimates %>% 
  filter(grepl(".*eventmove*.",labels)) %>% # keep only eventmove TEs
  mutate(labels = str_remove(labels,"_.*_")) %>% # keep only event period identifier
  rename(event_period = labels) %>% 
  pivot_longer( # reshape
    cols = `1995_men`:`2007_women`,
    names_to = c("cohort", "gender"),
    names_pattern = "(.*)_(.*)",
    values_to = c("estimates")) %>%
  pivot_wider(names_from = event_period, 
              values_from = estimates)

# Print sample dataset
kable(treatment_effects) %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "100%", height = "150px")
cohort gender m5 m4 m3 m2 m1 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
1995 men -2.6405290 -1.0233770 -1.8370580 -5.539949 0 24.8931400 19.873920 23.0116600 24.6096300 30.165560 35.787260 38.340190 47.52591 51.37444 57.05534 62.89460
1995 women -0.9536016 0.1850816 0.0274307 -2.022338 0 0.1993835 -3.100409 -2.8282450 -4.6091610 1.819559 5.000199 9.949792 14.94454 19.51605 25.55882 31.74741
1996 men -3.0547720 -1.3419440 -2.0536960 -5.682559 0 -1.8857990 -3.147631 0.7581085 9.7881370 19.027370 20.269940 29.890710 37.04669 45.33573 50.45368 53.55851
1996 women -1.2564440 -0.0501307 -0.1330074 -2.125625 0 -14.1422000 -20.327230 -17.6789100 -10.1881800 -4.165500 1.143028 6.837894 13.95172 20.65357 24.21982 31.68571
1997 men -3.2367920 -1.4900410 -2.1610960 -5.748987 0 6.0962630 4.931728 10.9912900 21.0580200 23.939290 33.837600 42.476780 48.02299 48.45209 51.15748 0.00000
1997 women -1.3405180 -0.1183245 -0.1851506 -2.169792 0 -15.4156900 -12.619870 -6.3550040 0.2417271 2.788401 10.845640 16.924060 19.79867 23.57125 28.08808 0.00000
1998 men -3.3033740 -1.5408470 -2.1962910 -5.776222 0 5.5003680 8.573675 20.4898500 21.2249200 28.148520 33.518610 39.017670 41.66799 47.40719 0.00000 0.00000
1998 women -1.4236160 -0.1799799 -0.2291071 -2.201792 0 -7.7877850 -4.855866 3.3000660 8.6929660 13.047940 16.023290 21.967710 25.98707 31.15330 0.00000 0.00000
1999 men -3.1182050 -1.3961850 -2.1025680 -5.722867 0 11.3229900 12.457290 15.3663200 23.0699400 28.426070 34.907400 37.956180 42.09329 0.00000 0.00000 0.00000
1999 women -1.3234620 -0.1075824 -0.1789874 -2.171325 0 -2.5627390 2.630906 7.2364410 10.6485600 14.301150 17.346560 21.593620 28.89363 0.00000 0.00000 0.00000
2000 men -3.3157200 -1.5614450 -2.2212280 -5.798105 0 17.7739800 12.458570 18.4137200 21.1658000 27.640240 30.416840 34.671570 0.00000 0.00000 0.00000 0.00000
2000 women -1.4159610 -0.1874839 -0.2407434 -2.206216 0 6.7720640 6.766865 10.3619000 14.4078100 17.206820 22.399540 26.988060 0.00000 0.00000 0.00000 0.00000
2001 men -3.1920280 -1.4569120 -2.1300140 -5.728381 0 7.8582930 6.127082 13.5551800 15.9334100 21.516380 25.310610 0.000000 0.00000 0.00000 0.00000 0.00000
2001 women -1.4029360 -0.1718986 -0.2218565 -2.187363 0 1.1922030 2.325496 6.4280400 9.5815770 11.378150 14.641110 0.000000 0.00000 0.00000 0.00000 0.00000
2002 men -3.2286910 -1.4834620 -2.1522940 -5.747120 0 0.0657903 -4.265936 1.4672100 -0.4709103 6.267400 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2002 women -1.1992270 -0.0078704 -0.1032168 -2.108216 0 -7.5992820 -7.680582 -5.1534050 -3.1676030 1.557755 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2003 men -3.0711700 -1.3564700 -2.0491850 -5.673895 0 -2.8334720 -10.314820 -7.9866050 -5.8191010 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2003 women -1.2993800 -0.0851668 -0.1546298 -2.142590 0 -14.2294800 -18.749770 -15.6204800 -8.0720880 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2004 men -3.2810690 -1.5249840 -2.1735190 -5.757267 0 -5.1726290 -12.717030 -5.7872640 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2004 women -1.3409240 -0.1176510 -0.1767365 -2.159660 0 -15.5960200 -17.071850 -10.1937000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2005 men -3.2383980 -1.4739690 -2.1340570 -5.734521 0 -2.9707380 -7.010961 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2005 women -1.3476040 -0.1169517 -0.1777445 -2.161676 0 -10.5259400 -8.542070 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2006 men -3.1401950 -1.4018230 -2.0824110 -5.698129 0 1.3055260 0.000000 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2006 women -1.2652420 -0.0487248 -0.1227247 -2.118451 0 -6.8831950 0.000000 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2007 men -3.0801470 -1.3505460 -2.0422680 -5.669942 0 0.0000000 0.000000 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000
2007 women -1.1713800 0.0262928 -0.0664935 -2.080385 0 0.0000000 0.000000 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.00000 0.00000

Traditional TWFE

The results from a standard TWFE event-study regression, using all cohorts, are extracted from the log-file here. I refer to these results as “traditional TWFE”.

Import

# Line skips, and gender vectors
line_skips_trad <- c(130,202)
import_trad_twfe <- function(line_skip, gender) {
  reg_output <- 
    read.table("../logs/analyze_twfe_main_couples.log",
               skip = line_skip, nrows = 30, header = FALSE, fill = TRUE) %>%
    as.data.frame() %>% # transform in data frame
    select(V1,V3) %>% # keep only labels and point estimates
    setNames(c("labels",paste0("trad_twfe_",gender))) %>% # change names to year_gender
    filter(grepl(".*eventmove*.",labels)) %>% # keep only eventmove TEs
    mutate(labels = str_remove(labels,"_.*_")) %>% # keep only event period identifier
    rename(event_period = labels)
  return(reg_output) # output of the function is a dataset with the regression results
}

# Apply function
trad_twfe_men <- import_trad_twfe(line_skips_trad[1],"men")
trad_twfe_women <- import_trad_twfe(line_skips_trad[2],"women")

Merge

trad_twfe <- 
  lapply(ls(pattern = "^trad"), get) %>% # create list with all datasets
  reduce(left_join, by = "event_period") # merge all by coefficient label

rm(list = ls(pattern="^trad_twfe_")) # delete gender-specific dataframes

# Print sample dataset
kable(trad_twfe) %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "100%", height = "150px")
event_period trad_twfe_men trad_twfe_women
m5 -5.862589 -2.1189780
m4 -3.910178 -0.9563359
m3 -4.201248 -0.9070012
m2 -6.996714 -2.6303310
m1 0.000000 0.0000000
p0 6.453778 -6.8742370
p1 5.190179 -6.6540240
p2 11.985340 -2.0661080
p3 17.809330 1.7784910
p4 24.309370 5.5423940
p5 31.480800 10.3408100
p6 37.932960 15.3375200
p7 44.402310 20.1492800
p8 51.190400 24.6461500
p9 56.953140 28.9405400
p10 64.303330 34.7177100

did_imputation

The results for the did_imputation command used with the hbalance and specific horizons were given to me in different log files. Here, I extract these estimates and merge them into a unique table.

Import

# Line skips, horizons, and gender vectors
line_skips_didimp <- c(125,217,454,935,578,1059)
horizons <- rep(c("m5p3","m5p5","m5p7"),2) %>% sort()
genders <- rep(c("men","women"),length(line_skips_didimp)/2)

# Import function
import_didimp <- function(horizon, line_skip, gender) {
  # Log file and number of rows in column are horizon-specific
  log_file <- ifelse(horizon=="m5p3",
                     "../logs/diagnostic_didimp_m5p3.log",
                     "../logs/diagnostic_didimp.log")
  nrows <- ifelse(horizon=="m5p3", 9, 
                  ifelse(horizon=="m5p5",11,
                         13))
  # Import tables
  didimp_output <-
    read.table(log_file, # read reg output
             skip = line_skip, nrows = nrows, header = FALSE, fill = TRUE) %>%
    as.data.frame() %>% # transform in data frame
    select(V1,V3) %>% # keep only labels and point estimates
    setNames(c("labels",paste0("didimp_",horizon,"_",gender))) %>% # change names to horizons_gender
    mutate(labels = str_replace(labels, "pre", "m")) %>% # transform pre`t' in mt
    mutate(labels = str_replace(labels, "tau", "p")) %>% # transform tau`t' in pt
    rename(event_period = labels)
  return(didimp_output)
}

# Apply function
for (i in 1:length(line_skips_didimp)) {
  assign(paste0("didimp_",horizons[i],"_",genders[i]), # save each output in one dataset
         import_didimp(horizon=horizons[i],line_skip=line_skips_didimp[i],gender=genders[i]))
}

rm(list = c("line_skips_didimp","horizons","genders")) # remove vectors

Merge

# Merge all regression outputs
did_imputation <- 
  lapply(ls(pattern = "^didimp"), get) %>% # create list with all datasets
  reduce(full_join, by = "event_period") %>% # merge all by coefficient label
  arrange(factor(event_period, levels = c(paste0("m",5:1),paste0("p",0:10)))) 

rm(list = ls(pattern="^didimp")) # delete horizon-specific dataframes

# Print sample dataset
kable(did_imputation) %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "100%", height = "150px")
event_period didimp_m5p3_men didimp_m5p3_women didimp_m5p5_men didimp_m5p5_women didimp_m5p7_men didimp_m5p7_women
m5 0.000000 0.0000000 0.000000 0.0000000 0.000000 0.0000000
m4 1.729601 1.1976720 1.729601 1.1976720 1.729601 1.1976720
m3 1.037880 1.1048860 1.037880 1.1048860 1.037880 1.1048860
m2 -2.589795 -0.9090057 -2.589795 -0.9090057 -2.589795 -0.9090057
m1 3.080147 1.1713800 3.080147 1.1713800 3.080147 1.1713800
p0 12.542780 -24.1522500 15.381770 -22.7352700 15.307460 -26.4474200
p1 11.347260 -25.3660000 15.137370 -22.9839400 15.912110 -26.0914700
p2 18.199680 -21.1708400 22.217690 -18.4739900 23.071760 -20.9766300
p3 22.757050 -15.9861100 27.977930 -13.2652300 29.859590 -15.2832300
p4 NA NA 34.925640 -7.3590370 36.837490 -8.7380750
p5 NA NA 39.855520 -1.2571070 43.160490 -2.5707440
p6 NA NA NA NA 48.472950 4.5249510
p7 NA NA NA NA 52.649430 10.8758100

Weights table from BJS

Before calculating the averages of the point estimates, I will define a table with weights from BJS, following Figure 2.6 from the 2022-08-29.pdf file. This table defines which cohort has available treatment effect estimates for each event period.

# Create table with weights
weights <- data.frame(cohort = c(1995:2007))
weights$m5_weight <- 1
weights$m4_weight <- 1
weights$m3_weight <- 1
weights$m2_weight <- 1
weights$m1_weight <- 1
weights$p0_weight <- c(rep(1, 12), rep(0,1))
weights$p1_weight <- c(rep(1, 11), rep(0,2))
weights$p2_weight <- c(rep(1, 10), rep(0,3))
weights$p3_weight <- c(rep(1, 9), rep(0,4))
weights$p4_weight <- c(rep(1, 8), rep(0,5))
weights$p5_weight <- c(rep(1, 7), rep(0,6))
weights$p6_weight <- c(rep(1, 6), rep(0,7))
weights$p7_weight <- c(rep(1, 5), rep(0,8))
weights$p8_weight <- c(rep(1, 4), rep(0,9))
weights$p9_weight <- c(rep(1, 3), rep(0,10))
weights$p10_weight <- c(rep(1, 2), rep(0,11))

# Print sample dataset
kable(weights) %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "100%", height = "150px")
cohort m5_weight m4_weight m3_weight m2_weight m1_weight p0_weight p1_weight p2_weight p3_weight p4_weight p5_weight p6_weight p7_weight p8_weight p9_weight p10_weight
1995 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1996 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1997 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1998 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
1999 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0
2000 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0
2001 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
2002 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0
2003 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
2004 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
2005 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
2006 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
2007 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0

Average estimates

Here, I calculate a simple average of the point estimate for each event period across cohorts, using all cohorts in all periods.

Subsequently, I calculate the averages only for the cohorts that contribute to the identification of every event time treatment effect in different time ranges, namely, from \(t=-5\) to \(t\in\{3,5,7\}\).

For example, for \(t\in[-5,3]\) – always \(t\in\mathbb{Z}\) – I only include cohorts from 1995 and 2003, and 2 cohorts are lost for each of the other sub intervals. The criteria to define which cohort contribute to each period is the weights table defined above.

All periods and all cohorts

# Create table with average estimates 
average_estimates <- treatment_effects %>%
  group_by(gender) %>% # group by gender
  summarise_at(vars(m5:p10), mean) %>% # calculate means for each event period
  mutate(periods = "cohort_twfe_all") %>% # create column that identifies method
  select(periods, gender, everything()) %>% # reorder columns
  mutate_all(as.character) # transform em character to facilitate append

Subset of periods and cohorts

To calculate the simple averages for subsets of periods, I define the function simple_avg_subset that calculates the average of the estimates for different intervals of time and append it to the average_estimates table.

Formally, what I am doing here is to calculate an average of the treatment effect for each event period across cohorts. Each \(\beta_t\) is defined as

\[\beta_t = \sum_{c=c_0}^{C^*}\frac{\beta_{t,c}}{C^*-c_0+1}.\] Note that the first cohort is always included, since it has treatment effect estimates for all event periods, so \(c_0=1995\). The last cohort to be included, however, depends on the time interval that is being evaluated. For \(t\in[-5,3]\) the last cohort that has point estimates for all these event periods is the 2003 one. Therefore, we have: \(t\in[-5,3]\Rightarrow C^*=2003\), \(t\in[-5,5]\Rightarrow C^*=2001\), and \(t\in[-5,7]\Rightarrow C^*=1999\).

# Function to calculate avg with subset of cohorts
simple_avg_subset <- function(t_final) {
  last_cohort <- 2006 - t_final
  averages <- treatment_effects %>%
    subset(cohort<=last_cohort) %>% # keep only cohorts of interest
    group_by(gender) %>% # group by gender
    summarise_at(vars(m5:paste0("p",t_final)), mean) %>% # calculate means for each event period
    mutate(periods = paste0("cohort_twfe_m5p",t_final)) %>% # create column that identifies method
    select(periods, gender, everything()) %>% # reorder columns
    mutate_all(as.character) # transform in character to facilitate append
  average_estimates <<- bind_rows(average_estimates, averages)
}

# Apply function for different periods
for (i in c(3,5,7)) {
  simple_avg_subset(t_final=i)
}

# Print sample dataset
kable(average_estimates) %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "100%", height = "150px")
periods gender m5 m4 m3 m2 m1 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
cohort_twfe_all men -3.14623769230769 -1.41553884615385 -2.102745 -5.713688 0 4.76567017692308 2.074299 6.94457457692308 10.0430650538462 14.2408330769231 16.4652507692308 17.1040846153846 16.6428361538462 14.8130346153846 12.2051153846154 8.95793153846154
cohort_twfe_all women -1.28771504615385 -0.0754146384615385 -0.1509975 -2.14272530769231 0 -6.6598985 -6.24802923076923 -2.34640746153846 1.34889293076923 4.45648269230769 6.72302823076923 8.02008738461539 7.96735615384615 7.29955153846154 5.98974769230769 4.87947076923077
cohort_twfe_m5p3 men -3.12903122222222 -1.40563144444444 -2.10038111111111 -5.71312055555556 0 7.64350592222222 5.18820866666667 10.6740815 14.5066495222222 NA NA NA NA NA NA NA
cohort_twfe_m5p3 women -1.29057173333333 -0.0803728444444444 -0.157696477777778 -2.14836188888889 0 -5.95261394444444 -6.17894 -2.25662188888889 1.9484009 NA NA NA NA NA NA NA
cohort_twfe_m5p5 men -3.12306 -1.40153585714286 -2.10027871428571 -5.71386714285714 0 10.2227478571429 8.75351914285714 14.6551612142857 19.5499795714286 25.5519185714286 30.5783228571429 NA NA NA NA NA
cohort_twfe_m5p5 women -1.30236265714286 -0.0900454857142857 -0.165917385714286 -2.15492157142857 0 -4.53496621428571 -4.16858685714286 0.0663268571428575 4.11075701428571 8.05378857142857 12.4856238571429 NA NA NA NA NA
cohort_twfe_m5p7 men -3.0707344 -1.3584788 -2.0701418 -5.6941168 0 9.1853924 8.5377964 14.1234457 19.9501294 25.941362 31.664162 37.536306 43.271374 NA NA NA
cohort_twfe_m5p7 women -1.25952832 -0.05418718 -0.13976436 -2.1381744 0 -7.9418061 -7.6544938 -3.2651304 0.95718242 5.55831 10.0717434 15.4546152 20.715126 NA NA NA

Append traditional TWFE results

Here, I append the traditional TWFE results to the average_estimates table, so we can use it to plot the results together.

append_trad_twfe <- function() {
  # Reshape trad_twfe
  reshaped_df <- trad_twfe %>%
    pivot_longer( # reshape
    cols = -c("event_period"),
    names_to = c("periods", "gender"),
    names_pattern = "(.*)_(.*)",
    values_to = c("estimates")) %>%
    pivot_wider(names_from = event_period, 
              values_from = estimates) %>%
    mutate_all(as.character) # transform in character to facilitate append
  # Append to average_estimates
  average_estimates <<- bind_rows(average_estimates, reshaped_df) 
}
# Apply function
append_trad_twfe()

Append did_imputation results

Now, I append the did_imputation results to the average_estimates table, so we can use it to plot the results together.

append_didimp <- function() {
  # Reshape did_imputation
  reshaped_df <- did_imputation %>%
    pivot_longer( # reshape
    cols = `didimp_m5p3_men`:`didimp_m5p7_women`,
    names_to = c("horizon", "gender"),
    names_pattern = "(.*)_(.*)",
    values_to = c("estimates")) %>%
    pivot_wider(names_from = event_period, 
              values_from = estimates) %>%
    rename(periods = horizon) %>%
    mutate_all(as.character) # transform in character to facilitate append
  # Append to average_estimates
  average_estimates <<- bind_rows(average_estimates, reshaped_df) 
}
# Apply function
append_didimp()

Figures – Treatment effects

Here, I plot the different estimation methods, namely, manual did_imputation using the TWFE cohort-specific regressions, and the actual did_imputation output.

# Function to plot estimates
plot_estimates <- function(interval) {
  # Adapts dataset
  plot_df <- average_estimates %>%
    filter(periods %in% interval) %>% # keep periods of interest
    pivot_longer(m5:p10, names_to = "event_period", values_to = "estimates") %>% # reshape
    mutate(event_period = str_replace(event_period, "m", "-")) %>% # transform m`t' in -t
    mutate(event_period = str_replace(event_period, "p", "")) %>% # transform p`t' in t
    mutate_at(c("event_period", "estimates"), as.numeric)  # transform variables in numeric
  # Figure
  plot <- plot_df %>%
    ggplot(aes(x=event_period, y=estimates, colour=periods, linetype=gender)) +
    geom_line(size = 1)  +
    geom_vline(xintercept=-.5, color="gray") + # vertical line before event
    scale_x_continuous(breaks = c(-5:10)) + 
    theme_classic() + 
    xlab("Event time") + ylab("Average estimate") +
    scale_color_discrete(name = "periods") +
    scale_linetype_discrete(name = "gender") +
    theme(panel.grid.major = element_line(linetype = "dotted"))
  return(plot)
}

All periods and all cohorts

plot_estimates(interval = c("cohort_twfe_all","trad_twfe"))

From -5 to 3

plot_estimates(interval = c("cohort_twfe_m5p3","trad_twfe","didimp_m5p3"))

From -5 to 5

plot_estimates(interval = c("cohort_twfe_m5p5","trad_twfe","didimp_m5p5"))

From -5 to 7

plot_estimates(interval = c("cohort_twfe_m5p7","trad_twfe","didimp_m5p7"))

Figures – Fixed effects

Year effects dataset

To facilitate the use of the dataset, I separate it only for year fixed effects coefficients.

# Create year effects dataset
year_effects <- 
  point_estimates %>% 
  filter(grepl(".*year*.",labels)) %>% # keep only year FEs
  mutate(labels = str_remove(labels,"_.*_")) %>% # keep only year info
  rename(year = labels) 
# Define plot function
plot_year_effects <- function() {
  # Adapts dataset
  plot_df <- year_effects %>%
    mutate_at("year", as.numeric) %>%
    pivot_longer( # reshape for graph
      cols = `1995_men`:`2007_women`,
      names_to = c("cohort", "gender"),
      names_pattern = "(.*)_(.*)",
      values_to = c("estimates"))
  # Figure
  plot <- plot_df %>%
    ggplot(aes(x=year, y=estimates, colour=cohort, linetype=gender)) +
    geom_line(size = .5)  +
    scale_x_continuous(breaks = c(1991:2006)) + 
    theme_classic() + 
    xlab("Year") + ylab("Point estimate") +
    scale_color_discrete(name = "cohort") +
    scale_linetype_discrete(name = "gender") +
    theme(panel.grid.major = element_line(linetype = "dotted"))
  return(plot)
}
plot_year_effects() 

Child effects dataset

To facilitate the use of the dataset, I separate it only for child fixed effects coefficients.

# Create year effects dataset
child_effects <- 
  point_estimates %>% 
  filter(grepl(".*child*.",labels)) %>% # keep only eventmove TEs
  mutate(labels = str_remove(labels,"_.*_")) %>% # keep only event period identifier
  rename(event_period = labels) 
# Define plot function
plot_child_effects <- function() {
  # Adapts dataset
  plot_df <- child_effects %>%
    mutate(event_period = str_replace(event_period, "m", "-")) %>% # transform m`t' in -t
    mutate(event_period = str_replace(event_period, "p", "")) %>% # transform p`t' in t
    # Below, I transform no_child in 13 - remember to relabel it in graph
    mutate(event_period = str_replace(event_period, "no_child1","13")) %>% 
    mutate_at("event_period", as.numeric) %>%
    pivot_longer( # reshape for graph
      cols = `1995_men`:`2007_women`,
      names_to = c("cohort", "gender"),
      names_pattern = "(.*)_(.*)",
      values_to = c("estimates"))
  # Figure
  plot <-
    ggplot(mapping = aes(x=event_period, y=estimates, colour=cohort)) +
    geom_line(data = subset(plot_df,event_period<13), 
              aes(linetype=gender),size=.5)  +
    geom_point(data = subset(plot_df,event_period==13)) +
    scale_x_continuous(breaks = c(-1:10,13),
                       labels = c(as.character(c(-1:10)),"No child")) + 
    theme_classic() + 
    xlab("Event time") + ylab("Point estimate") +
    scale_color_discrete(name = "cohort") +
    scale_linetype_discrete(name = "gender") +
    theme(panel.grid.major = element_line(linetype = "dotted"))  
  return(plot)
}
plot_child_effects()