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

From |
Howard Lempel <HLempel@brookings.edu> |

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

Subject |
st: RE: Code erroring out because of "no observations" |

Date |
Thu, 25 Jun 2009 16:44:26 -0400 |

Hi Ariel, In your loop, _N represents the number of total observations, not the total number of waves. There are only 15 waves of data, so when i gets to 16, you get an error - there are no observations for which wave==16. I think you want to change your loop to the following: forvalues i=2/15 { logit union l.ln_wage l.age l.collgrad l.tenure l.hours if wave==`i' predict pred`i' if wave == `i' } If you don't want to stick 15 in as a magic number, you could to the following: sum wave local max = r(max) forvalues i=2/`max' { logit union l.ln_wage l.age l.collgrad l.tenure l.hours if wave==`i' predict pred`i' if wave == `i' } Hope this helps. Howie -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Marcello Pagano Sent: Thursday, June 25, 2009 4:29 PM To: statalist@hsphsun2.harvard.edu Subject: st: Code erroring out because of "no observations" From: Ariel Linden, DrPH [mailto:ariel.linden@gmail.com] Sent: Wednesday, June 24, 2009 2:40 PM To: 'owner-statalist@hsphsun2.harvard.edu' Subject: Code erroring out because of "no observations" Hi All, I am running some code in the nlswork file in which I use lagged values in the present period’s logit model. Since there are individuals in the file that don’t have more than one period (wave), the code errors with “no observations.” As a result, the code cannot continue to the last line I have below which generates a variable with the max of all the waves. I tried using “capture” but the loop never ends. I’d appreciate it if someone could tell me how to override the error and continue on to the next line of code? (if my poor coding could be improved as well, I’d appreciate that as well) ☺ Thanks in advance Ariel ***** start of code********** webuse nlswork, clear sort idcode year bysort idcode: egen wave = seq() tsset idcode wave logit union age collgrad tenure hours if wave==1 predict pred1 if e(sample) forvalues i=2/`=_N' { logit union l.ln_wage l.age l.collgrad l.tenure l.hours if wave==`i' predict pred`i' if wave == `i' } egen predfinal = rowmax( pred*) ***** end of code************* * * 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: Code erroring out because of "no observations"***From:*Marcello Pagano <pagano@hsph.harvard.edu>

- Prev by Date:
**st: Code erroring out because of "no observations"** - Next by Date:
**Re: st: Code erroring out because of "no observations"** - Previous by thread:
**st: Code erroring out because of "no observations"** - Next by thread:
**Re: st: Code erroring out because of "no observations"** - Index(es):

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