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
Maximizing Sharpe Ratio - Portfolio optimizationHi, I would like to maximize the Sharpe ratio (=Historical Return (portfolio)/Standard deviation(po…
Suppress input prompt for pauseFantastic people of Statalist, I am running a batch of do files that contain -pause- commands and w…
Hausman test has suggested Random effects model but I want to use Fixed effectsHello everyone, I am using EU dataset for 27 countries for 5 different years. My goal is to determi…
returnsyh command donwloads historical data for any ticker with historical data in Yahoo - ErrorHi, I am getting the following error with returnsyh command donwloads historical data for any ticke…
Repeated observations in panel data Dear all, I am trying to build a long database. I have data from 2004 to 2018 where, during four y…
Subscribe to:
Post Comments (Atom)
0 Response to Exporting confidence intervals that loop through all vars in an excel format
Post a Comment