Statalist


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

Re: st: while loop


From   Steven Samuels <sjhsamuels@earthlink.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: while loop
Date   Fri, 4 Jul 2008 14:11:51 -0400

-rolling-



-Steve


On Jul 4, 2008, at 1:31 PM, Indrit Hoxha wrote:

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



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index