Statalist


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

st: RE: -forval- with -inequal7-


From   Lola Jackson <[email protected]>
To   [email protected]
Subject   st: RE: -forval- with -inequal7-
Date   Tue, 15 Jul 2008 09:09:07 +0000 (GMT)

(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 <[email protected]>
wrote:
 
> From: Nick Cox <[email protected]>
> Subject: st: RE: -forval- with -inequal7-
> To: [email protected]
> 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 
> [email protected] 
> 
> 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/



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