Statalist The Stata Listserver

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

st: loop breaks if missing value

Subject   st: loop breaks if missing value
Date   Mon, 17 Jul 2006 11:38:01 -0400

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

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

Olga Gorbachev Melloni
Economics Ph.D. Student
Columbia University

*   For searches and help try:

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