[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Martin Weiss" <[email protected]> |

To |
<[email protected]> |

Subject |
st: AW: writing svy:tabulate confidence intervals to one file for many variables |

Date |
Wed, 16 Sep 2009 13:45:42 +0200 |

```
<>
To get your hands on the CIs conveniently, use Ben Jann`s -estpost- command
which you can get by typing -ssc inst estout- in web-aware Stata.
There is an example in the help file for -estpost- addressing your problem.
Type -help estpost, mark(svy_tabulate)- to get there...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Paul Shattuck
Gesendet: Mittwoch, 16. September 2009 13:34
An: [email protected]
Betreff: st: writing svy:tabulate confidence intervals to one file for many
variables
Dear Statalist Users,
Overall Problem I am Trying to Solve:
I have many dichotomous (0,1) indicators in a survey dataset and would
like to create files of tabular results that are easy to open in Excel
summarizing the proportion of "yes" responses and related confidence
intervals for many variables in one combined table (in order to avoid
copying and pasting tabular results one at a time from the Results
window after a series of individual svy:tabulate commands).
Partial Solution Achieved:
I successfully created the macro below to write a tab-delimited file
that contains the variable names, variable labels, proportion of "yes"
responses, observed (unweighted) counts of "yes" responses, and the
observed subpopulation counts for a series of variables (one row per
variable).
Specific Problem That I Cannot Solve:
I cannot figure out how to include 95% confidence intervals in this
macro so that the newly created file table of results includes columns
for the lower and upper bounds. Stata uses a logit transform to
construct the confidence intervals reports in the Results window when
you run svy:tab, as explained in the svy:tab documentation. However, I
have not been able to figure out how to compute the confidence intervals
based on the postestimation scalars and matrices that are saved after
running the svy: tabulate oneway command. (The confidence interval
bounds that appear in the results table from svy:tabulate are not saved
as scalar or matrix values for postestimation as far as I can tell).
QUESTION for Statalist Users:
Do you have any ideas about how to derive the confidence interval bounds
from the svy:tab postestimation scalars and matrices and include them in
the tab delimited results file?
Here is my routine that successfully creates a tab-delimited file like
the example below:
<assume a survey data file is already open and we have run svyset>
file open tabs using "C:<filename>.txt", write replace
file write tabs "variable" _tab "var label" _tab "proportion yes" _tab
"n yes" _tab "subpop n" _n
set more off
foreach var of varlist x1 x2 x3 x4 {
svy brr, subpop(if subpopvar==1) mse:
tab `var' , obs percent ci
matrix p=e(b)
local pyes = el(p, 1, 2)
matrix zz=e(ObsSub)
local nyes = el(zz, 2, 1)
file write tabs %9s "`var'" _tab %7.8f
(e(rowvlab)) _tab %7.8f "`pyes'" ///
_tab %7.0f "`nyes'" _tab %7.0f
(e(N_sub)) _n
}
file close tabs
e(b) is the postestimation matrix of proportions. The "matrix p" command
creates a callable matrix from e(b). The 'local pyes' command creates a
local variable equal to the proportion answering "yes" (values of 1) by
using the el function for "summoning" a specific matrix element.
Likewise, "local nyes" summons the matrix element denoting the number of
"1" observations (unweighted) in the analyzed subpopulation.
This macro creates a tab-delimited file like this (this output is fake)
that is easy to open in Excel:
Variable val label proportion n yes sample n
X1 x1 label 0.345 3450 10000
X2 x2 label 0.123 1230 10000
X3 x3 label 0.789 7890 10000
Thank you in advance,
Paul T. Shattuck
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
```

**References**:**st: writing svy:tabulate confidence intervals to one file for many variables***From:*"Paul Shattuck" <[email protected]>

- Prev by Date:
**st: generated regressor and GMM** - Next by Date:
**RE: st: truncreg:could not calculate numerical derivatives** - Previous by thread:
**st: writing svy:tabulate confidence intervals to one file for many variables** - Next by thread:
**st: truncreg:could not calculate numerical derivatives** - Index(es):

© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |