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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

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

Subject |
st: Re: Code erroring out because of "no observations" - revisited |

Date |
Sat, 27 Jun 2009 01:48:45 +0200 |

*** webuse nlswork, clear xtdes *** to see the participation pattern. If you want to see why you drop to 12 (not 11, not 13, either) type *** webuse nlswork, clear by idcode, sort : egen float nonmiss = count(union) su nonmiss *** BTW, even with these problems, your code runs fine for me... HTH Martin _______________

To: <statalist@hsphsun2.harvard.edu> Sent: Saturday, June 27, 2009 1:31 AM Subject: st: Code erroring out because of "no observations" - revisited

Hi Again,I reran the updated code (as per Howie's suggestion, see below), and itran fine. However, when I first dropped all individuals where union ==.the code failed at the last wave (12). Stata gave an error r(9777); whichhas no help associated with it.I think it has something with how it reads the last wave (12), becausewhen I set the code to run only through 11 waves it works fine. Again, allhelp is welcome:**** start code**** *webuse nlswork, clear bysort idcode (year):gen wave = _n tsset idcode wave drop if union==. logit union ln_wage age collgrad tenure hours if wave==`i' predict ps1 if e(sample) 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 ps`i' if wave == `i' } egen psfinal = rowmax(ps*) ***** end code****** Date: Thu, 25 Jun 2009 16:44:26 -0400 From: Howard Lempel <HLempel@brookings.edu> Subject: st: RE: Code erroring out because of "no observations" Hi Ariel,In your loop, _N represents the number of total observations, not thetotal number of waves. There are only 15 waves of data, so when i gets to16, 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 thefollowing: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 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 inthe present periodâ€™s logit model. Since there are individuals in thefile that donâ€™t have more than one period (wave), the code errors withâ€œno observations.â€ As a result, the code cannot continue to the lastline I have below which generates a variable with the max of all thewaves.I tried using â€œcaptureâ€ but the loop never ends.Iâ€™d appreciate it if someone could tell me how to override the error andcontinue on to the next line of code? (if my poor coding could be improvedas 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" - revisited***From:*"Ariel Linden, DrPH" <ariel.linden@gmail.com>

- Prev by Date:
**st: RE: pass quotes in a local macro** - Next by Date:
**st: stata2mplus convert mac file name to PC file name** - Previous by thread:
**st: Re: Code erroring out because of "no observations" - revisited** - Next by thread:
**st: stata2mplus convert mac file name to PC file name** - Index(es):

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