Hi all,
I am running a diff-in-diff based on individuals who were present in six waves of the data looking seven outcome variables. However, there are differences in the number of observations as not all individuals may respond to a question in every wave. The diff-in-diff is run separately by post time periods (July 2020, Sep 2020 and Jan 2021 compared against a baseline period of 2017-2019) which makes it harder to save the estimation sample and then re-run the other estimations based on a particular estimation sample. Does anyone have any ideas whether it's possible to ensure the same number of observations in a set up like this? In the code below, my goal is to have a constant number of observations between (1) and (2) where I only keep observations for individuals who responded to this particular question for both July 2020 and Jan 2021.
keep if inlist(wave,9,15,16,17,18,19)
bys pidp: keep if _N == 6
global controls_dx agecat_sec educ_ref race_main jbstat_ref cathhincome_ref mhvalue_ref_casenessc marstat_ref nchild015_ref hhsize_ref ///
gor_main imonth_final
(1) diff dfruit_simp, t(treatfem) p(July2020) cov($controls) cluster(pidp)
(2) diff dfruit_simp, t(treatfem) p(Jan2021) cov($controls) cluster(pidp)
Many thanks
Karen
I am running a diff-in-diff based on individuals who were present in six waves of the data looking seven outcome variables. However, there are differences in the number of observations as not all individuals may respond to a question in every wave. The diff-in-diff is run separately by post time periods (July 2020, Sep 2020 and Jan 2021 compared against a baseline period of 2017-2019) which makes it harder to save the estimation sample and then re-run the other estimations based on a particular estimation sample. Does anyone have any ideas whether it's possible to ensure the same number of observations in a set up like this? In the code below, my goal is to have a constant number of observations between (1) and (2) where I only keep observations for individuals who responded to this particular question for both July 2020 and Jan 2021.
keep if inlist(wave,9,15,16,17,18,19)
bys pidp: keep if _N == 6
global controls_dx agecat_sec educ_ref race_main jbstat_ref cathhincome_ref mhvalue_ref_casenessc marstat_ref nchild015_ref hhsize_ref ///
gor_main imonth_final
(1) diff dfruit_simp, t(treatfem) p(July2020) cov($controls) cluster(pidp)
(2) diff dfruit_simp, t(treatfem) p(Jan2021) cov($controls) cluster(pidp)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long pidp byte wave float(dfruit_simp treatfem July2020 Jan2021 agecat_sec educ_ref race_main jbstat_ref cathhincome_ref mhvalue_ref_casenessc marstat_ref nchild015_ref hhsize_ref gor_main imonth_final) 76165 9 1 1 0 0 0 . 1 1 3 0 1 1 3 5 4 76165 15 1 1 1 . 1 . 1 1 3 0 1 1 3 5 7 76165 16 . 1 . . 1 . 1 1 3 0 1 1 3 5 9 76165 17 . 1 . . 1 . 1 1 3 0 1 1 3 5 11 76165 18 1 1 . 1 1 . 1 1 3 0 1 1 3 5 1 76165 19 . 1 . . 1 . 1 1 3 0 1 1 3 5 3 1587125 9 1 1 0 0 2 . 0 1 2 0 0 0 2 1 9 1587125 15 0 1 1 . 2 . 0 1 2 0 0 0 2 1 7 1587125 16 . 1 . . 2 . 0 1 2 0 0 0 2 1 9 1587125 17 . 1 . . 2 . 0 1 2 0 0 0 2 1 11 1587125 18 1 1 . 1 2 . 0 1 2 0 0 0 2 1 1 1587125 19 . 1 . . 2 . 0 1 2 0 0 0 2 1 3 4849085 9 0 0 0 0 0 1 1 1 3 1 1 0 3 11 4 4849085 15 1 0 1 . 1 1 1 1 3 1 1 0 3 11 7 4849085 16 . 0 . . 1 1 1 1 3 1 1 0 3 11 9 4849085 17 . 0 . . 1 1 1 1 . 1 1 0 3 11 11 4849085 18 1 0 . 1 1 1 1 1 3 1 1 0 3 11 1 4849085 19 . 0 . . 1 1 1 1 3 1 1 0 3 11 3 68002725 9 0 1 0 0 2 . 0 4 1 0 0 0 1 7 3 68002725 15 0 1 1 . 3 . 0 4 1 0 0 0 1 7 7 68002725 16 . 1 . . 3 . 0 4 1 0 0 0 1 7 9 68002725 17 . 1 . . 3 . 0 4 1 0 0 0 1 7 11 68002725 18 0 1 . 1 3 . 0 4 1 0 0 0 1 7 1 68002725 19 . 1 . . 3 . 0 4 1 0 0 0 1 7 3 68008847 9 1 1 0 0 2 0 1 1 1 0 0 0 1 1 3 68008847 15 1 1 1 . 2 0 1 1 . 0 0 0 1 1 7 68008847 16 . 1 . . 2 0 1 1 1 0 0 0 1 1 9 68008847 17 . 1 . . 2 0 1 1 1 0 0 0 1 1 11 68008847 18 0 1 . 1 2 0 1 1 . 0 0 0 1 1 1 68008847 19 . 1 . . 2 0 1 1 1 . 0 0 1 1 3 68010887 9 1 1 0 0 2 1 1 1 2 0 1 0 2 1 3 68010887 15 1 1 1 . 2 1 1 1 2 0 1 0 2 1 7 68010887 16 . 1 . . 2 1 1 1 2 0 1 0 2 1 9 68010887 17 . 1 . . 2 1 1 1 2 0 1 0 2 1 11 68010887 18 0 1 . 1 2 1 1 1 . 0 1 0 2 1 1 end
Karen
Comment