Statalist


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

st: -forval- with -inequal7-


From   Lola Jackson <[email protected]>
To   [email protected]
Subject   st: -forval- with -inequal7-
Date   Mon, 14 Jul 2008 17:11:59 +0000 (GMT)

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!)

Thanks,
Lola



      __________________________________________________________
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/



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