Hello to all,
I am trying to plot the means of a dichotomous variable "dredisatt", by country over 4 time points.
The problem is that only one of the 4 countries has all 4 time points. The others have gaps.
When I try to combine the 4 subgraphs (marginsplots) with a single legend (grc1leg2), the resulting legend is incorrect.
Here is an example of my dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(dredisatt obsub7b wave country)
1 . 1 1
1 . 1 1
1 . 1 1
0 0 4 1
0 6 4 1
1 3 4 1
1 5 4 1
1 5 1 2
1 . 1 2
1 5 4 2
1 3 4 2
1 3 4 2
1 5 2 3
1 6 3 3
0 0 3 3
0 3 2 4
1 0 2 4
0 2 2 4
. 0 3 4
1 1 3 4
end
label values dredisatt dredisatt
label def dredisatt 0 "Don't agree", modify
label def dredisatt 1 "Agree", modify
label values obsub7b obsub7b
label def obsub7b 0 "Working class concordant", modify
label def obsub7b 1 "Working class inflator", modify
label def obsub7b 2 "Middle class deflator", modify
label def obsub7b 3 "Middle class concordant", modify
label def obsub7b 5 "Service class deflator", modify
label def obsub7b 6 "Service class concordant", modify
label values wave wave
label def wave 1 "1992", modify
label def wave 2 "1999", modify
label def wave 3 "2009", modify
label def wave 4 "2019", modify
label values country country
label def country 1 "DE", modify
label def country 2 "IT", modify
label def country 3 "NO", modify
label def country 4 "US", modify
And an example of my code:
Code:
local a1 = "de"
local a2 = "it"
local a3 = "no"
local a4 = "us"

local c1 ib1.obsub7b##ib1.wave if country==1
local c2 ib1.obsub7b##ib1.wave if country==2
local c3 ib2.obsub7b##ib1.wave if country==3
local c4 ib1.obsub7b##ib1.wave if country==4

local h = 1

forvalues i = 1/4 {
quietly anova dconflict `c`i'' [aw=WEIGHT]
    margins ib1.obsub7b#ib1.wave
    marginsplot, title("`a`h''", size(small)) name(`a`h''conflict) recast(scatter) ///
    legend(row(1)) yscale(range(0 1)) xlabel(, angle(vertical) labsize(vsmall)) ytitle("") xtitle("") noci nodraw legend(off)
    local h = `h' + 1
}
*
grc1leg deconflict itconflict noconflict usconflict, title("Proportion perceiving strong class conflict in Germany, Italy, Norway and the United States", size(small)) name(allconflict) ///
ycommon rows(1) l1title("Proportion supporting income distribution", size(vsmall))
Array

The 4 subgraphs come out, but for example in the 2nd subgraph "it", according to the legend we have data for years 1992, 1999 and 2009. But the correct 3 time points in the data are 1992, 2009 and 2019. Hence my question: how can I modify the script so that each subgraph corresponds correctly to the legend?
Thank you!