Hi, I am doing a DiD on affective polarisation between parties from 2022-2023 and that works fine. However, now I want to plot the pre-treatment trends and therefore merged data from 2011, 2015 and 2019 into my dataset. I am wanting to do a plot that one of my professors has a dofile for. apRBS1 is my outcome variable, TG =0 if control and =1 if treatment group, and year is my time variable, I have repeated cross-sectional data which is why I don't use cluster. The command looks like this:
reg apRBS1 TG##year, r
margins, at(TG=(0 1) year=(2011 (4) 2023)) post
mat A = e(b)
global M00 = A[1,1]
global M01 = A[1,2]
global M02 = A[1,3]
global M03 = A[1,4]
global M04 = A[1,5]
global M10 = A[1,7]
global M11 = A[1,8]
global M12 = A[1,9]
global M13 = A[1,10]
global M14 = A[1,11]
global M10c = A[1,7]
global M11c = A[1,7]+(A[1,2]-A[1,1])
global M12c = A[1,9]+(A[1,3]-A[1,2])
global M13c = A[1,9]+(A[1,4]-A[1,2])
global M14c = A[1,9]+(A[1,5]-A[1,2])
tw (scatteri $M00 2011 $M01 2015 $M02 2019 $M03 2022 $M04 2023, connect(line) m(o) mc(gs10) lc(gs10)) (scatteri $M10c 2011 $M11c 2015 $M12c 2019 $M13c 2022 $M14c 2023, connect(line) m(o) mc(gs10) lc(gs10) mc(gs10) lp(dash)) (scatteri $M10 2011 $M11 2015 $M12 2019 $M13 2022 $M14 2023, connect(line) m(o)), xlabel(2011 (4) 2023) xscale(range(2010.9 2023.1)) ylabel(,nogrid) xtitle(År) ytit("Affektiv polarisering", size(medsmall)) legend(label (3 "Treatmentgruppens udvikling") label (2 "Kontrakfaktisk udvikling") label (1 "Kontrolgruppens udvikling") order(1 3 2) position(6))
With control variables it works except
margins, at(TG=(0 1) year=(2011 (4) 2023)) post "at level for factor year not present during estimation r(198);"
And the plot doesn't look right since for my control group it says that it has the maximum level of my outcome variable in 2015, which is not true.
I tried to run it without controls but running the regression it says:
note: 0b.TG#2011b.year identifies no observations in the sample.
note: 0b.TG#2015.year identifies no observations in the sample.
note: 0b.TG#2019.year identifies no observations in the sample.
note: 1.TG#2015.year omitted because of collinearity.
note: 1.TG#2019.year omitted because of collinearity.
note: 1.TG#2023.year omitted because of collinearity.
however it does want to do the margins now. When I tab TG and year, there are observations for all values in all years, so I don't get why it says this^^.
I am not that good with graphs in stata, so I have looked at lots of posts in here for alternative plots or explanations but most of the commands people give don't work for me and I can't seem to figure out what is wrong. (I have done a simple plot of means over time for control- and treatment group but that is just not as accurate as the DiD post one).
Sorry for the long post, I hope someone can help me! Thank you!
reg apRBS1 TG##year, r
margins, at(TG=(0 1) year=(2011 (4) 2023)) post
mat A = e(b)
global M00 = A[1,1]
global M01 = A[1,2]
global M02 = A[1,3]
global M03 = A[1,4]
global M04 = A[1,5]
global M10 = A[1,7]
global M11 = A[1,8]
global M12 = A[1,9]
global M13 = A[1,10]
global M14 = A[1,11]
global M10c = A[1,7]
global M11c = A[1,7]+(A[1,2]-A[1,1])
global M12c = A[1,9]+(A[1,3]-A[1,2])
global M13c = A[1,9]+(A[1,4]-A[1,2])
global M14c = A[1,9]+(A[1,5]-A[1,2])
tw (scatteri $M00 2011 $M01 2015 $M02 2019 $M03 2022 $M04 2023, connect(line) m(o) mc(gs10) lc(gs10)) (scatteri $M10c 2011 $M11c 2015 $M12c 2019 $M13c 2022 $M14c 2023, connect(line) m(o) mc(gs10) lc(gs10) mc(gs10) lp(dash)) (scatteri $M10 2011 $M11 2015 $M12 2019 $M13 2022 $M14 2023, connect(line) m(o)), xlabel(2011 (4) 2023) xscale(range(2010.9 2023.1)) ylabel(,nogrid) xtitle(År) ytit("Affektiv polarisering", size(medsmall)) legend(label (3 "Treatmentgruppens udvikling") label (2 "Kontrakfaktisk udvikling") label (1 "Kontrolgruppens udvikling") order(1 3 2) position(6))
With control variables it works except
margins, at(TG=(0 1) year=(2011 (4) 2023)) post "at level for factor year not present during estimation r(198);"
And the plot doesn't look right since for my control group it says that it has the maximum level of my outcome variable in 2015, which is not true.
I tried to run it without controls but running the regression it says:
note: 0b.TG#2011b.year identifies no observations in the sample.
note: 0b.TG#2015.year identifies no observations in the sample.
note: 0b.TG#2019.year identifies no observations in the sample.
note: 1.TG#2015.year omitted because of collinearity.
note: 1.TG#2019.year omitted because of collinearity.
note: 1.TG#2023.year omitted because of collinearity.
however it does want to do the margins now. When I tab TG and year, there are observations for all values in all years, so I don't get why it says this^^.
I am not that good with graphs in stata, so I have looked at lots of posts in here for alternative plots or explanations but most of the commands people give don't work for me and I can't seem to figure out what is wrong. (I have done a simple plot of means over time for control- and treatment group but that is just not as accurate as the DiD post one).
Sorry for the long post, I hope someone can help me! Thank you!
Comment