[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Larraine Becker <lbecker@unimelb.edu.au> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
RE: st: RE: Output summary stats before doing other iteration |

Date |
Mon, 15 Sep 2008 10:39:34 +1000 |

Martin I tried a program define and simulate but I couldn't get it working. I'm only starting to use Stata, so it's all very challenging for me!! Can I just write my code with program define above it and end below it? Is there somewhere more help for this? Thanks, Larraine -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss Sent: Friday, 12 September 2008 5:46 PM To: statalist@hsphsun2.harvard.edu Subject: RE: st: RE: Output summary stats before doing other iteration True! Seems like a textbook case for -simulate- as I suggested yesterday http://www.stata.com/statalist/archive/2008-09/msg00392.html. In fact, I cannot see what is saved inside the loop. The -summarize- line would throw up output for the screen, but if you want to save characteristics of the predictions, -simulate- is the way to go... HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eva Poen Sent: Friday, September 12, 2008 9:31 AM To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: Output summary stats before doing other iteration Larraine, please don't use html for your postings to statalist (see the advice in the faq). It would be interesting to see the -if- statement in your logit regression. Is it -if dropouts==1-? If I understand correctly, your procedure is - generate random variable for sorting - run logistic regression on a (random) subsample of your data, which excludes all observations that have been used in previous iterations - generate predicted values for _all_ observations in the dataset. First, whenever you work with random numbers, you should set the random number seed in order to make your results reproducible: set seed 123 for example. Next, it seems perfectly sufficient to save the estimation result during the loop. You can use estimates store iteration`i' within your loop, and then generate predicted values as and if you need them: estimates for iteration723 : predict onehat723 See -help estimates-. Do you really want to generate 1000 variables with predicted values? If you tell us what you ultimately want to achive, we might be able to suggest something more suitable. It looks as if you are doing a simulation exercise of some sort; there might be a more direct way. Hope this helps, Eva 2008/9/12 Larraine Becker <lbecker@unimelb.edu.au>: > Just a correction, the program below is wrong.it should be: > > > > forvalues i=1(1)10 { > > use "U:\CS\combined dataset_2006.dta", clear > > generate random`i' = uniform() > > sort anyprevcs random`i' > > generate dropouts = 0 > > replace dropouts =1 if anyprevcs==1 & (_N - _n) < 3575 > > > > logit ...(I've deleted the variables, as there are too many to put here!) > > > > replace anyprevcs=0 if dropouts==1 > > predict onehat`i' > > summarize onehat`i' > > drop dropouts n > > } > > > > > > ________________________________ > > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Larraine Becker > Sent: Friday, 12 September 2008 4:35 PM > To: statalist@hsphsun2.harvard.edu > Subject: st: Output summary stats before doing other iteration > > > > Hi all, > > > > I'm doing 1000 iterations of a logistic regression. I have to output the > predicted value each time before it carries on with the next iteration, > otherwise I lose the > > first 999 predicted values! I'm sure there is a way to go about this, but > how can I save the predicted value each time so I end up with a table with > 1000 predicted values? > > > > My program is as follows: > > > > forvalues i=1(1)10 { > > use "U:\CS\combined dataset_2006.dta", clear > > generate random`i' = uniform() > > sort anyprevcs random`i' > > generate dropouts = 0 > > replace dropouts =1 if anyprevcs==1 & (_N - _n) < 3575 > > > > logit ...(I've deleted the variables, as there are too many to put here!) > > > > replace anyprevcs=0 if dropouts==1 > > predict onehat`i' > > summarize onehat`i' > > gen n=_n > > egen predicted`i'=mean(onehat`i')*n > > drop dropouts n > > } > > > > Thanks, > > Larraine * * 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/ * * 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/

**Follow-Ups**:**Re: st: RE: Output summary stats before doing other iteration***From:*"Eva Poen" <eva.poen@gmail.com>

**References**:**st: Output summary stats before doing other iteration***From:*Larraine Becker <lbecker@unimelb.edu.au>

**st: RE: Output summary stats before doing other iteration***From:*Larraine Becker <lbecker@unimelb.edu.au>

**Re: st: RE: Output summary stats before doing other iteration***From:*"Eva Poen" <eva.poen@gmail.com>

- Prev by Date:
**RE: st: RE: Output summary stats before doing other iteration** - Next by Date:
**st: Heteroscedasticity and auto-correlation in fixed effect panel data** - Previous by thread:
**RE: st: RE: Output summary stats before doing other iteration** - Next by thread:
**Re: st: RE: Output summary stats before doing other iteration** - Index(es):

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