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

From |
Liss Palamkunnel <liss789@yahoo.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: RE: -forval- with -inequal7- |

Date |
Tue, 15 Jul 2008 08:45:25 -0700 (PDT) |

Lola, If you are sure you have all years from 1990 - 2007 and all quarters for those years you can add an additional forvalue in your loop. g gini=. forval i = 1990/2007 { forvalu q=1/4 { inequal7 income [fw=wei] if date==`i'`q', returns replace gini=r(gini) if date==`i' } } --- On Tue, 7/15/08, philippe van kerm <philippe.vankerm@ceps.lu> wrote: > From: philippe van kerm <philippe.vankerm@ceps.lu> > Subject: st: RE: RE: -forval- with -inequal7- > To: "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> > Date: Tuesday, July 15, 2008, 6:43 AM > Lola, > > -inequal7- exits with an error message when run on a > (sub-)sample of 0 observations. Some commands do work in > this case (e.g. summarize), others don't (e.g. > regress). > > A simple workaround here is to -capture- the output of > -inequal7- > > g gini=. > qui forval i = 19901/20071 { > capture inequal7 income [fw=wei] if date==`i', > returns > replace gini=r(gini) if date==`i' > } > > But it would probably be cleaner to loop only over valid > 'dates'. See the FAQ suggested by Nick Cox: > http://www.stata.com/support/faqs/data/foreach.html > > Philippe > > > -----Original Message----- > > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner- > > statalist@hsphsun2.harvard.edu] On Behalf Of Lola > Jackson > > Sent: Tuesday, July 15, 2008 11:09 AM > > To: statalist@hsphsun2.harvard.edu > > Subject: st: RE: -forval- with -inequal7- > > > > > > (I've been trying to send this message since > yeterday but it's not > > appearing on the statalist, hope it does now...) > > > > > > > > Apologies for some typos in my previous query, I > copied and pasted my > > code into my message and then modified it for the > various commands but > > mixed them up in the email.. However, this is not the > problem. An error > > message arises whenever there is a 'missing' > date, using -inequal7-. > > > > The codes I have tried are as follows: > > > > using forval: > > > > g gini=. > > qui forval i = 19901/20071 { > > inequal7 income [fw=wei] if date==`i', returns > > replace gini=r(gini) if date==`i' > > } > > > > and using foreach: > > > > g gini=. > > qui foreach i of num 19901/20071 { > > inequal7 income [fw=wei] if date==`i', returns > > replace gini=r(gini) if date==`i' > > } > > > > But with both get the error message: > > '0' invalid obs no > > r(198); > > > > These do work when limited to 'consecutive' > dates (eg 19901/19904), the > > problem arises when they span 'missing' dates > as there is no 19905. > > The programme runs and calculates the gini for the > dates up until a > > 'missing' date and then stops with an error. > This is not a problem with > > other commands using the same dataset, but has arisen > with -inequal7-. > > > > Thanks, > > Lola > > > > > > > > > > --- On Mon, 7/14/08, Nick Cox > <n.j.cox@durham.ac.uk> > > wrote: > > > > > From: Nick Cox <n.j.cox@durham.ac.uk> > > > Subject: st: RE: -forval- with -inequal7- > > > To: statalist@hsphsun2.harvard.edu > > > Date: Monday, July 14, 2008, 5:44 PM > > > -inequal7- is blameless here. > > > > > > Your -forval- syntax, at least as given here, is > > incorrect. > > > > > > > > > forval i = 19901/20071 { > > > > > > You must have an equals sign. See the help on > > -forvalues-, > > > including all > > > the examples given. > > > > > > Similarly, your first example with -foreach- has > > incorrect > > > syntax. > > > > > > You cannot mix and match the two syntaxes. Also, > > guessing > > > at syntax you > > > would like or imagine might work is all too > likely just > > to > > > cause > > > frustration. > > > > > > Given the gaps, you might be better advised to > check > > out > > > solutions > > > documented at > > > > > > FAQ . . . . . > > . . . . . Making foreach go through all > > > values of a > > > variable > > > 8/05 Is there a way to tell Stata to > try all > > > values of a > > > particular variable in a foreach > statement > > > without > > > specifying them? > > > > > > > http://www.stata.com/support/faqs/data/foreach.html > > > > > > Nick > > > n.j.cox@durham.ac.uk > > > > > > Lola Jackson > > > > > > I am using -forval- to run -inequal7- by date and > > export > > > selected > > > results. The problem is that I get the error > message: > > > > > > '0' invalid obs no > > > r(198); > > > > > > I think the reason is that by dates are not > > > 'consecutive' in that I have > > > 19901, 19902, 19903, 19904, then 19911, 19912, > etc. (As > > > there are > > > quarterly observations for each year 1990, 1991 > etc). > > From > > > various tests > > > I have concluded that the error arises when the > loop > > tries > > > to run for a > > > date when there are no observations (eg 19905). > > > > > > My code is: > > > qui forval i 19901/20071 { > > > inequal7 income [fw=wei] if date==`i', > returns > > > replace gini=r(gini) if date==`i' > > > } > > > > > > I also tried using -foreach- but got the same > error > > > message: > > > qui foreach i = 19901/20071 { > > > inequal7 income [fw=wei] if date==`i', > returns > > > replace gini=r(gini) if date==`i' > > > } > > > > > > The only way that it works is if I specify each > date > > > individually, as > > > in: > > > qui foreach i in 19901 19902 19903 **etc** { > > > inequal7 income [fw=wei] if date==`i', > returns > > > replace gini=r(gini) if date==`i' > > > } > > > > > > But this means typing each date individually. > > > > > > I have run -forval- in this way for the same > dataset, > > > without problems, > > > the problem seems to arise when combined with > > -inequal7-. > > > > > > I would welcome any suggestions as to how to > correct > > the > > > problem (or > > > even a smarter way of doing what I need!) > > > > > > > > > * > > > * For searches > > and help try: > > > * > http://www.stata.com/support/faqs/res/findit.html > > > * http://www.stata.com/support/statalist/faq > > > * http://www.ats.ucla.edu/stat/stata/ > > > > ________________________________ > > Not happy with your email address? > > Get the one you really want - millions of new email > addresses > > available now at Yahoo! > > > > > > > __________________________________________________________ > > Not happy with your email address?. > > Get the one you really want - millions of new email > addresses available > > now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html > > > > > > > > * > > * For searches and help try: > > * http://www.stata.com/support/faqs/res/findit.html > > * http://www.stata.com/support/statalist/faq > > * http://www.ats.ucla.edu/stat/stata/ > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: RE: RE: -forval- with -inequal7-***From:*philippe van kerm <philippe.vankerm@ceps.lu>

- Prev by Date:
**[no subject]** - Next by Date:
**Re: st: RE: Help with data management** - Previous by thread:
**st: RE: RE: -forval- with -inequal7-** - Next by thread:
**st: RE: RE: -forval- with -inequal7-** - Index(es):

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