Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Tim Evans <Tim.Evans@wmciu.nhs.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found |

Date |
Fri, 18 Nov 2011 15:36:43 +0000 |

Nick, Richard Thanks for your comments regarding this, and apologies for not responding back sooner. One query I did have was that I wasn't getting exact confidence intervals and I think I have located this in how I was calculating them - below are my steps to resolving them. My final example is at the bottom, altough I'm not happy with how the data are stored in the data file - as will be obvious with the end code. My first example gave used the following code: **BEGIN EXAMPLE** clear all sysuse auto, clear recode rep78 1/2=3 recode foreign (0/1=.) if trunk==10 ice rep78 foreign mpg, clear m(5) seed(1234) saving(impauto) replace mim: proportion rep78, over(foreign) matrix bmat = e(MIM_Q) matrix vmat = e(MIM_T) forval j = 1/4 { gen prop`j' = bmat[1,`j'] gen se`j' = vmat[`j', `j'] ^ .5 gen se_`j'b = se`j'* 1.96 gen lower`j' = prop`j' - se_`j'b gen upper`j' = prop`j' + se_`j'b } sum prop* se* lower* upper* collapse (mean) prop* se* lower* upper* **END EXAMPLE** I think the problem being that I was using 1.96 on a small number of observations. When I looked up the degrees of freedom and a more accurate 95% CI level (for 49 degrees of freedom it is 2.010). If this is used in the code, the CIs are much closer.: This would not be ideal if I were running this across numerous datasets as I wouldn't want to manually look up the degrees of freedom and amend the code. My final example used this code: **BEGIN EXAMPLE** clear all sysuse auto, clear recode rep78 1/2=3 recode foreign (0/1=.) if trunk==10 ice rep78 foreign mpg, clear m(5) seed(1234) saving(impauto) replace mim: proportion rep78, over(foreign) matrix bmat = e(MIM_Q) matrix vmat = e(MIM_T) forval j = 1/4 { gen prop`j' = bmat[1,`j'] gen se`j' = vmat[`j', `j'] ^ .5 gen dof`j' = e(MIM_dfmin) gen lower`j' = prop`j' - se`j' * invttail(dof`j', 0.025) gen upper`j' = prop`j' + se`j' * invttail(dof`j', 0.025) gen id`j' = `j' } sum prop* se* lower* upper* collapse (mean) prop* se* lower* upper* id* order prop1 se1 lower1 upper1 prop2 se2 lower2 upper2 prop3 se3 lower3 upper3 prop4 se4 lower4 upper4 **END EXAMPLE While this gives me comparable results to three decimal places (it may be better with a larger dataset) its not perfect, but I cant unpick what -proportion- is doing. I have two questions: 1) Is there a better way of ordering my results than my final line of code as I may have more than 4 proportions and associated CIs?: order prop1 se1 lower1 upper1 prop2 se2 lower2 upper2 prop3 se3 lower3 upper3 prop4 se4 lower4 upper4 2) This may be a job for -reshape-, but I would much rather have the data set out in columns like: Number Proportion se lci uci 1 .781 .060 .665 .907 2 xx xx xx xx 3 etc Rather than continuing along one line. Can anyone offer any help? Best wishes Tim -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tim Evans Sent: 07 November 2011 12:06 To: 'statalist@hsphsun2.harvard.edu' Subject: RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found Thanks Nick, That sorted out my standard error calculation a treat - I had no idea about ^. Just need to follow through to the confidence intervals. Does anyone know how -proportion- does calculate CIs? I think my example gives similar, but not identical CIs now I have amended the code and wanted to know what it was doing differently. I've tried to look at the .ado file, but it was quite empty and have looked at the help file which pointed me to -ratios-, which does show the standard error calculation, but not the CIs. Best wishes Tim -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 07 November 2011 12:01 To: 'statalist@hsphsun2.harvard.edu' Subject: RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found Stata uses ^ for powering. ** clearly is something used in various other programs, but never Stata so far as I can recall. Nick n.j.cox@durham.ac.uk -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tim Evans Sent: 07 November 2011 11:38 To: 'statalist@hsphsun2.harvard.edu' Subject: RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found Hi Richard, Thanks for your reply. I've had a go at implementing this code, but I don't get the same standard errors as what are in my output table, and as such the confidence intervals do not match either. In the original code there was a double asterisk for this code: gen se`j' = vmat[`j', `j'] **.5, I removed this as I had an error message saying 'bmat not found' I'm still unsure about how to convert the total covariance matrix estimate e(MIM_T) into the standard error. Apologies if this is basic math. This is my example with the auto data: BEGIN EXAMPLE: clear all sysuse auto, clear recode rep78 1/2=3 recode foreign (0/1=.) if trunk==10 ice rep78 foreign mpg, clear m(5) seed(1234) saving(impauto) replace mim: proportion rep78 matrix bmat = e(MIM_Q) matrix vmat = e(MIM_T) forval j = 1/4 { gen prop`j' = bmat[1,`j'] gen se`j' = vmat[`j', `j'] * .5 gen se_`j'b = se`j'* 1.96 gen lower`j' = prop`j' - se_`j'b gen upper`j' = prop`j' + se_`j'b } sum prop* se* lower* upper* collapse (mean) prop* se* lower* upper* list in 1/1 ***END CODE*** Best wishes Tim -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Richard Williams Sent: 04 November 2011 21:18 To: statalist@hsphsun2.harvard.edu Subject: RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found At 08:45 AM 11/4/2011, Tim Evans wrote: >I've realised I would like the confidence intervals also. But I'm >not sure I can find the right values in -ereturn list- that will >allow me to calculate the CIs. Can anyone help? First, you want the square roots of the diagonals of the variance matrix, i.e. the standard errors. After -mim-, this matrix is stored in e(MIM_T). Or, just use the -storebv- option, and you get stuff stored in e(b) and e(V). The (untested) code will be something like this: matrix bmat = e(MIM_Q) matrix vmat = e(MIM_T) forval j = 1/4 { gen prop`j' = bmat[1,`j'] gen se`j' = bmat[`j', `j'] ** .5 gen lower`j' = se`j' * -1.96 + prop`j' gen upper`j' = se`j' * 1.96 + prop`j' } sum prop* se* lower* upper* collapse (mean) prop* se* lower* upper* I am assuming the sample is large and that 1.96 is the appropriate critical value. If small you may need to use the appropriate T value instead. Make sure that the data set matches what the proportion command gave you - it is possible I am doing something wrong here, i.e. given that this is a proportion I might have the formula wrong, in which case you need to hunt down the right formula for the CI. >-----Original Message----- >From: owner-statalist@hsphsun2.harvard.edu >[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tim Evans >Sent: 04 November 2011 11:39 >To: 'statalist@hsphsun2.harvard.edu' >Subject: RE: st: SOLVED! saving -proportion- estimates to a .dta or >.csv file last estimates not found > >Ignore last post, have just had another google search and found this >helpful thread: > >http://statalist.1588530.n2.nabble.com/mim-and-parmest-td5013352.html > >from Martin Weiss which shows that mim does not store estimates in >e(b) rather e(MIM_Q). > >Updated code is this: > >proportion stage >matrix bmat = e(MIM_Q) >forval j = 1/4 { >gen prop`j' = bmat[1,`j'] >} >sum prop* >collapse (mean) prop* > >Best wishes > >Tim > > > >-----Original Message----- >From: owner-statalist@hsphsun2.harvard.edu >[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tim Evans >Sent: 04 November 2011 11:31 >To: 'statalist@hsphsun2.harvard.edu' >Subject: RE: st: saving -proportion- estimates to a .dta or .csv >file last estimates not found > >Having tried both methods suggest by Maarten and Richard, I think >Richard's will work best, but I have a problem in that I am using >this on a multiple imputed dataset. When I run the analysis, I am >returned with an error (details below): > >mim: proportion stage if _mj>0 & inrange(yydx,1985,1989) >matrix bmat = e(b) > >last estimates not found >r(301) > >yet when I run this: > >proportion stage if _mj>0 & inrange(yydx,1985,1989) >matrix bmat = e(b) >forval j = 1/4 { >gen prop`j' = bmat[1,`j'] >} >sum prop* >collapse (mean) prop* > > >Its absolutely fine - but not what I want. > >Any suggestions appreciated. > > >-----Original Message----- >From: owner-statalist@hsphsun2.harvard.edu >[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Richard Williams >Sent: 03 November 2011 18:27 >To: statalist@hsphsun2.harvard.edu >Subject: Re: st: saving -proportion- estimates to a .dta or .csv file > >At 11:54 AM 11/3/2011, Tim Evans wrote: > >I'm trying to save and export the proportion estimates I obtain from > >using -proportion- into a useable data file, either .csv or .dta. > > > >However having googled this and looked at help resources with > >-proportion- I don't seem to find what I am after. > > > >How would I return the results from the following code into a data file: > > > >sysuse auto > >proportion rep78 , over(foreign) > >The estimates are ereturned in e(b). If nothing else you could >generate variables equal to those values, cut your data set down to >one case, and save under a new name. Something like > >sysuse auto >proportion rep78 , over(foreign) >matrix bmat = e(b) >forval j = 1/10 { >gen prop`j' = bmat[1,`j'] >} >sum prop* ------------------------------------------- Richard Williams, Notre Dame Dept of Sociology OFFICE: (574)631-6668, (574)631-6463 HOME: (574)289-5227 EMAIL: Richard.A.Williams.5@ND.Edu WWW: http://www.nd.edu/~rwilliam * * 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/ _DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. * * 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/ _DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. * * 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/ _DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. * * 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: weights for a longitudinal set (Was: probable error, "weights invalid" using stset]***From:*<S.Jenkins@lse.ac.uk>

**st: saving -proportion- estimates to a .dta or .csv file***From:*Tim Evans <Tim.Evans@wmciu.nhs.uk>

**RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found***From:*Tim Evans <Tim.Evans@wmciu.nhs.uk>

**RE: st: Confidence intervals: saving -proportion- estimates to a .dta or .csv file last estimates not found***From:*Tim Evans <Tim.Evans@wmciu.nhs.uk>

- Prev by Date:
**st: RE: new package margdistfit available on SSC** - Next by Date:
**st: new version hangroot available from SSC** - Previous by thread:
- Next by thread:
**st: Calculation of covariance matrix for unbalanced sample?** - Index(es):