Statalist


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

st: while loop


From   Indrit Hoxha <Indrit.Hoxha@mail.uh.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: while loop
Date   Fri, 04 Jul 2008 12:31:45 -0500

I have a panel dataset with countries and years. I am trying to do some regressions for every country in windows of 5 years. I want these 5 years to be overlapping so for example for United States, I want the first regression to be for 1980-1984, the second 1981-1985, third 1982-1986 and goes on like this. I have used loop within a loop to do this. As you can see from the do file below

local i=1

while `i'<131 {

local j=1980

while `j'< 2006 {

reg y  x1 x2 x3  if cc==`i' & (year==`j'|year ==`j'+1|year ==`j'+2|year ==`j'+3|year ==`j'+4)

local j= `j'+1

}

local i= `i'+1

}

However I have missing data for some countries and years, so when the loop starts if it does not find any data for the first country and first group of years the do file stops.
Could someone help me out here, how should I do these regressions.
I'd really appreciate any help .
 
Indrit Hoxha
PhD Candidate
University of Houston
Department of Economics


 



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