Code:
* Example generated by -dataex-. For more info, type help dataex clear input long group int week_id float(outcome start_treatment) byte treatment float Start_TreatmentxTreatment 43018 1 0 0 1 0 43018 2 0 0 1 0 43018 3 0 0 1 0 43018 4 0 0 1 0 43018 5 0 0 1 0 43018 6 0 0 1 0 43018 7 0 0 1 0 43018 8 0 0 1 0 43018 9 0 0 1 0 43018 10 0 0 1 0 43018 11 0 0 1 0 43018 12 0 0 1 0 43018 13 0 0 1 0 43018 14 .0008872458 0 1 0 43018 15 .001749846 0 1 0 43018 16 0 0 1 0 43018 17 0 0 1 0 43018 18 0 0 1 0 43018 19 0 0 1 0 43018 20 0 0 1 0 43018 21 0 0 1 0 43018 22 0 0 1 0 43018 23 0 0 1 0 43018 24 .000961183 0 1 0 43018 25 0 0 1 0 43018 26 .001848429 0 1 0 43018 27 .0009118916 0 1 0 43018 28 .0008872458 0 1 0 43018 29 .002686383 0 1 0 43018 30 .005274184 0 1 0 43018 31 .0008626001 0 1 0 43018 32 0 1 1 1 43018 33 0 1 1 1 43018 34 0 1 1 1 43018 35 0 1 1 1 43018 36 .009414664 1 1 1 43018 37 0 1 1 1 43018 38 0 1 1 1 43018 39 0 1 1 1 43018 40 0 1 1 1 43018 41 0 1 1 1 43018 42 0 1 1 1 43018 43 0 1 1 1 43018 44 .0015280345 1 1 1 43018 45 0 1 1 1 43018 46 .0014540973 1 1 1 43018 47 .0007147258 1 1 1 43018 48 .0006900801 1 1 1 43018 49 .0014540973 1 1 1 43018 50 0 1 1 1 43018 51 0 1 1 1 43018 52 0 1 1 1 43043 1 0 0 0 0 43043 2 0 0 0 0 43043 3 0 0 0 0 43043 4 0 0 0 0 43043 5 0 0 0 0 43043 6 0 0 0 0 43043 7 0 0 0 0 43043 8 0 0 0 0 43043 9 0 0 0 0 43043 10 0 0 0 0 43043 11 0 0 0 0 43043 12 .00118411 0 0 0 43043 13 0 0 0 0 43043 14 0 0 0 0 43043 15 0 0 0 0 43043 16 0 0 0 0 43043 17 0 0 0 0 43043 18 0 0 0 0 43043 19 .011077158 0 0 0 43043 20 0 0 0 0 43043 21 0 0 0 0 43043 22 0 0 0 0 43043 23 0 0 0 0 43043 24 .0012987013 0 0 0 43043 25 .0012987013 0 0 0 43043 26 .005194805 0 0 0 43043 27 0 0 0 0 43043 28 0 0 0 0 43043 29 0 0 0 0 43043 30 .003590527 0 0 0 43043 31 .003705118 0 0 0 43043 32 0 1 0 0 43043 33 0 1 0 0 43043 34 .002330023 1 0 0 43043 35 .002330023 1 0 0 43043 36 0 1 0 0 43043 37 0 1 0 0 43043 38 0 1 0 0 43043 39 0 1 0 0 43043 40 .0022154315 1 0 0 43043 41 0 1 0 0 43043 42 .0021772345 1 0 0 43043 43 0 1 0 0 43043 44 0 1 0 0 43043 45 0 1 0 0 43043 46 0 1 0 0 43043 47 0 1 0 0 43043 48 0 1 0 0 43043 49 0 1 0 0 43043 50 0 1 0 0 43043 51 0 1 0 0 43043 52 0 1 0 0 43075 1 0 0 1 0 43075 2 0 0 1 0 43075 3 0 0 1 0 43075 4 0 0 1 0 43075 5 0 0 1 0 43075 6 0 0 1 0 43075 7 0 0 1 0 43075 8 0 0 1 0 43075 9 0 0 1 0 43075 10 0 0 1 0 43075 11 0 0 1 0 43075 12 0 0 1 0 43075 13 0 0 1 0 43075 14 0 0 1 0 43075 15 0 0 1 0 43075 16 0 0 1 0 43075 17 0 0 1 0 43075 18 0 0 1 0 43075 19 0 0 1 0 43075 20 0 0 1 0 43075 21 0 0 1 0 43075 22 0 0 1 0 43075 23 0 0 1 0 43075 24 0 0 1 0 43075 25 0 0 1 0 43075 26 0 0 1 0 43075 27 0 0 1 0 43075 28 0 0 1 0 43075 29 0 0 1 0 43075 30 0 0 1 0 43075 31 0 0 1 0 43075 32 0 1 1 1 43075 33 0 1 1 1 43075 34 0 1 1 1 43075 35 0 1 1 1 43075 36 0 1 1 1 43075 37 0 1 1 1 43075 38 0 1 1 1 43075 39 0 1 1 1 43075 40 0 1 1 1 43075 41 0 1 1 1 43075 42 0 1 1 1 43075 43 0 1 1 1 43075 44 0 1 1 1 43075 45 0 1 1 1 43075 46 0 1 1 1 43075 47 0 1 1 1 43075 48 0 1 1 1 43075 49 0 1 1 1 43075 50 0 1 1 1 43075 51 0 1 1 1 43075 52 0 1 1 1 43081 1 0 0 1 0 43081 2 0 0 1 0 43081 3 0 0 1 0 43081 4 0 0 1 0 43081 5 0 0 1 0 43081 6 0 0 1 0 43081 7 0 0 1 0 43081 8 0 0 1 0 43081 9 0 0 1 0 43081 10 0 0 1 0 43081 11 0 0 1 0 43081 12 0 0 1 0 43081 13 0 0 1 0 43081 14 0 0 1 0 43081 15 0 0 1 0 43081 16 0 0 1 0 43081 17 0 0 1 0 43081 18 0 0 1 0 43081 19 0 0 1 0 43081 20 0 0 1 0 43081 21 0 0 1 0 43081 22 0 0 1 0 43081 23 0 0 1 0 43081 24 0 0 1 0 43081 25 0 0 1 0 43081 26 0 0 1 0 43081 27 .0030801494 0 1 0 43081 28 .006094764 0 1 0 43081 29 0 0 1 0 43081 30 0 0 1 0 43081 31 0 0 1 0 43081 32 0 1 1 1 43081 33 0 1 1 1 43081 34 0 1 1 1 43081 35 0 1 1 1 43081 36 0 1 1 1 43081 37 0 1 1 1 43081 38 0 1 1 1 43081 39 0 1 1 1 43081 40 0 1 1 1 43081 41 0 1 1 1 43081 42 0 1 1 1 43081 43 0 1 1 1 43081 44 0 1 1 1 43081 45 0 1 1 1 43081 46 0 1 1 1 43081 47 0 1 1 1 43081 48 0 1 1 1 43081 49 0 1 1 1 43081 50 0 1 1 1 43081 51 0 1 1 1 43081 52 0 1 1 1 end
Hello. This is a manipulated version of a small chunk of a dataset I have been working with. This dataset contains 52 observations for each group in reality.
Treatment is a dummy indicating whether a member of group was randomly selected to receive a treatment.
Start_treatment indicates the start of the treatment period, which occurs during the same week_id for each group member.
Start_TreatmentxTreatment is equivelant to treatment*start_treatment. It is a 1 for group members that received the treatment after the start of treatment, but not before, and a 0 for everyone else.
Don't worry about the fact that there are a lot of 0s in the outcome. The actual dataset contains many observations. Some groups have more 0s than others.
I have created a difference in difference model for this dataset, and I have been asked to create margins plots for it. Here is the code I have been using for the DiD model and the margins plots:
The DiD model can either be modeled as:
1.
Code:
xtreg outcome i.treatment i.start_treatment i.week_id i.treatmentt#start_treatment, fe cluster(zip)
2.
Code:
xtreg outcome Start_TreatmentxTreatment i.treatment i.start_treatment i.week_id, fe cluster(zip)
What I would like to do is create a margins predicted outcome means plot that shows the treatment and control group both before and after the treatment for both. The problem is that due to the colinearity problems that arise with the treatment dummy being 1 for every group, and the start of treatment being the same for every group, I am not able to calculate margins in a way that allows for proper estimation of margins for the treatment group in the pre-treatment period.
When I try to run:
Code:
xtreg outcome i.treatment i.start_treatment i.week_id i.treatmentt#start_treatment, fe cluster(zip) margins treatment#start_treatment at(week_id=(1(1)52))
Code:
xtreg outcome Start_TreatmentxTreatment i.treatment i.start_treatment i.week_id, fe cluster(zip)[ margins Start_TreatmentxTreatmentt#start_treatment, at(week_id=(1(1)52))
I have to imagine there is some standard solution to this problem that allows for calculating margins plots for DiD models for both the treatment, and control, in both the before and after treatment period, even when collinearity is present. My dataset is not unusual and I don't know how people have been creating margins plots for DiD models over the years without running into this exact same problem.
I would greatly appreciate any assistance. Please let me know if you need me to answer clarifying questions. I am new to this level of statistical work, and I'm writing this late on a Friday night so I apologize for any lack of clarity or technical ambiguities.
0 Response to How to calculate a margins plot for a DiD model when faced with colinearity issues?
Post a Comment