I am trying to replace margins command after the three-level multilevel model with a lower-level interaction effect fitted in runmlwin (Stata/SE 15.1).
The single-level regression analysis is written as follows with margins command at the end:
Code: Select all
reg stfdem_s c.f_polintr_n##(c.dev_ideology c.dev_environment c.dev_equality c.dev_values c.dev_immigration c.dev_euintegration) ///
female_n eduyrs_n stfeco_n stfhlth_n stfedu_n dis_gall_n single_majority minimal_coalition surplus_coalition single_minority multi_minority ///
i.country [aweight=dweight]
foreach var of varlist dev_ideology dev_environment dev_equality dev_values dev_immigration dev_euintegration {
local title : variable label `var'
margins, at(`var'=(0(.1)1) f_polintr_n=(0 1))
marginsplot, recast(line) recastci(rarea) ///
title("`title'") ///
xtitle("congruence") ///
ytitle("predicted satisfaction") ylabel(40(5)65) ///
legend(order(3 "low interest in politics" 4 "high interest in politics") col(1)) ///
name(`var', replace)
}
graph combine dev_ideology dev_environment dev_equality dev_values dev_immigration dev_euintegration
graph export test_combine.png
Now, I write the three-level model with runmlwin:
Code: Select all
sort country cabinet idno
set seed 1073741823
quietly runmlwin stfdem_s cons ///
int1 int2 int3 int4 int5 int6 ///
dis_gall_n ///
single_majority minimal_coalition surplus_coalition single_minority multi_minority ///
dev_ideology dev_environment dev_equality dev_values dev_immigration dev_euintegration ///
female_n eduyrs_n f_polintr_n stfeco_n stfhlth_n stfedu_n, ///
level3(country: cons f_polintr_n) level2(cabinet: cons) level1(idno: cons) nopause
display "`c(current_time)' `c(current_date)'"
runmlwin stfdem_s cons ///
int1 int2 int3 int4 int5 int6 ///
dis_gall_n ///
single_majority minimal_coalition surplus_coalition single_minority multi_minority ///
dev_ideology dev_environment dev_equality dev_values dev_immigration dev_euintegration ///
female_n eduyrs_n f_polintr_n stfeco_n stfhlth_n stfedu_n, ///
level3(country: cons f_polintr_n) level2(cabinet: cons) level1(idno: cons) ///
mcmc(cc burnin(5000) chain(50000) hcen(3)) initsprevious nopause zratio
display "`c(current_time)' `c(current_date)'"
Code: Select all
* (1) Set variables to zero except for the variables of interest:
local unwanted = "int2 int3 int4 int5 int6 dis_gall_n single_majority minimal_coalition surplus_coalition single_minority multi_minority dev_environment dev_equality dev_values dev_immigration dev_euintegration female_n eduyrs_n stfeco_n stfhlth_n stfedu_n"
foreach var in `unwanted' {
replace `var' = 0
}
* Predict
predict yhat
predict yhat_se, stdp
gen yhat_lb = yhat - 1.96 * yhat_se
gen yhat_ub = yhat + 1.96 * yhat_se
* Plot the results for the first interaction: Dev_ideology * political interest
twoway (rarea yhat_ub yhat_lb dev_ideology if f_polintr_n == 0, sort fcolor(blue) fintensity(inten10) lstyle(grid)) ///
(rarea yhat_ub yhat_lb dev_ideology if f_polintr_n == 1, sort fcolor(red) fintensity(inten10) lstyle(grid)) ///
(line yhat dev_ideology if f_polintr_n == 0, lcolor(blue)) ///
(line yhat dev_ideology if f_polintr_n == 1, lcolor(red)) ///
(histogram dev_ideology, percent yaxis(2) color(gs10%70) width(0.05) ytitle(Percentage of observations, axis(2))), ///
bgcolor(white) graphregion(color(white)) scale(0.7) ytitle(Predicted 'Satisfaction With Democracy') ///
legend(order(1 "Low interest in politics: 95 per cent confidence intervals" 2 "High interest in politics: 95 per cent confidence intervals" 3 "Predicted values: low political interest" 4 "Predicted values: high political interest") cols(1))
graph save int1_ideology, replace
graph export int1_ideology.png, replace
Subsequently, I repeat these codes for each interaction term.
I have the following question:
(1) Is this the right way to produce results similar to the margins command when I specify the variable political interest as 0 and 1 for low and high political interest?
I include the specification of the margins command here for convenience:
Code: Select all
margins, at(`var'=(0(.1)1) f_polintr_n=(0 1))
Best regards,
Rza