Statalist The Stata Listserver


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

st: RE: loop breaks if missing value is encountered


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: loop breaks if missing value is encountered
Date   Mon, 17 Jul 2006 16:53:16 +0100

I don't know what a "missing observation" is. 

A value of a variable can be missing in a particular observation
(case or record, in non-Stata terminology). Missing for 
Stata means an empty string for string variables or one of 
. .a ... .z for numeric variables. 

Or, you can look for a value of a variable but find that there 
is no observation with such a value in the data. It is 
not present. (You can say that it is "missing", but this 
is strictly wrong in Stata terms and usually confusing.)  

There are completely different situations. I don't know
which is yours. However, there is advice at 

http://www.stata.com/support/faqs/data/foreach.html

which may apply to your problem. Note that typing 

. search loop

would have pointed you to this FAQ. 

In particular, the answer may be to use -capture-. 

Nick 
[email protected] 

Olga Gorbachev Melloni
 
> I am trying to run rolling prais regressions with a panel data set,
> rolling command seems not to be working well for this purpose (I
> already posted with that question and so far no solution was
> found).
> 
> I wrote a small loop to do the same, the problem is that I have an
> unbalanced panel dataset and as soon as missing observation is
> encountered, the loop brakes (I tried 'tsfill, full' and replacing
> all missing with 99999999, but then prais regression doesn't like
> that either and the loop breaks again).
> 
> Is there a way to write the loop to skip those missing observations,
> put a missing value into the "anwswer" and continue on?
> 
> Here is the main code:
> 
> forvalues y=1973/1996 {
>    gen resid`y'=.
>    gen pred`y'=.
>          forvalues i=1/3824 {
>             prais r exp if (year>=`y'-14 & year<=`y') & s==`i'
>            predict r if e(sample), resid
>             predict p if e(sample)
>             replace resid`y'=r if (year>=`y'-4 & year<=`y') & s==`i'
>             replace pred`y'=p if (year>=`y'-4 & year<=`y') & s==`i'
>            drop r p
>          }
> }
> 

*
*   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