For each of my regional data files, I am trying to export confidence interval tables in a csv file. The current output in STATA looks like below, which I would like to replicate in an excel table.
Variable | Obs | Mean | Std. Err. | [95% Conf. Interval]
-------------+---------------------------------------------------------------
accept_vio~n | 330 .3364758 .02605 .2852303 .3877213
However, when I use the code below, the output does not include the variable, nor does it include the observation number. Any advice would be greatly appreciated, as I have tried a number of different solutions on this forum. Thank you.
#delimit;
clear;
use "Dta Files\2019_Indonesia_Weighted_DM.dta";
drop if geographies_DM != 1;
recode city (12=3)(13=2)(14=1), gen (sundacity);
label define sundacity
1"West Nusa Tenggara"
2"East Nusa Tenggara"
3"Bali";
label values sundacity sundacity;
cap postclose ci_results_sunda;
postfile ci_results_sunda var obs mean se lowerCI upperCI using "2019_ci_results_sunda.dta", replace;
foreach var of varlist optimist-accept_violence_religion {;
ci `var'[aweight=weight_pop];
ci `var' if sundacity==3 [aweight=weight_pop];
ci `var' if sundacity==2 [aweight=weight_pop];
ci `var' if sundacity==1 [aweight=weight_pop];
ci `var' if age_group_DM==4 [aweight=weight_pop];
ci `var' if age_group_DM==3 [aweight=weight_pop];
ci `var' if age_group_DM==2 [aweight=weight_pop];
ci `var' if age_group_DM==1 [aweight=weight_pop];
ci `var' if religion_all_DM==4 [aweight=weight_pop];
ci `var' if religion_all_DM==3 [aweight=weight_pop];
ci `var' if religion_all_DM==2 [aweight=weight_pop];
ci `var' if religion_all_DM==1 [aweight=weight_pop];
ci `var' if female_DM==2 [aweight=weight_pop];
ci `var' if female_DM==1 [aweight=weight_pop];
ci `var' if urban_DM==2 [aweight=weight_pop];
ci `var' if urban_DM==1 [aweight=weight_pop];
post ci_results_sunda (`var') (r(obs)) (r(mean)) (r(se)) (r(lb)) (r(ub));
};
postclose ci_results_sunda;
use ci_results_sunda.dta, clear;
use "2019_ci_results_sunda.dta";
outsheet using "ci_results_sunda.csv", comma replace;
Related Posts with Exporting confidence intervals that loop through all vars in an excel format
Including only time effects in model - how to test specificationHi, Stata users, thank you all for sharing your knowledge and help others! I have panel data, and t…
How to simplify conditional statementsDear all, Code: * Example generated by -dataex-. To install: ssc install dataex clear input float(…
Significance stars into the coefplotDear stata users, is there a way how to include the significance stars into the coefplot? The probl…
How to export file after regression?Hi everyone, I started learning STATA recently after learning some object-oriented programming lang…
How to choose between Pooled OLS/Random Effects?Hello, I am currently working on my undergrad thesis with the topic factor determinants for imports…
Subscribe to:
Post Comments (Atom)
0 Response to Exporting confidence intervals that loop through all vars in an excel format
Post a Comment