Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: forcing loops through errors
From
Linh Vuong <[email protected]>
To
[email protected]
Subject
st: forcing loops through errors
Date
Tue, 26 Jul 2011 23:14:53 -0700
Stata/IC 11.2 for Mac (64-bit Intel)
Born 30 Mar 2011
Hello Statalist!
I'm trying to write a loop that runs through 6 variables: VO_Sev
EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev, for 2000-2011. This is what I
tried:
forvalues year=2000/2011 {
foreach varname of varlist VO_Sev EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev {
reg killed `varname' if startyear2==`year'
reg totaffected `varname' if startyear2==`year'
reg estdamageusmillion `varname' if startyear2==`year'
}
}
The first problem I encounter is an error message that says "No
observations", which is true for some of these regressions. However,
I'd like Stata to continue with the loop and do the next regression.
How can I make Stata continue the loop even though it's finding an
error?
The second thing I'd like it to do is to add a variable in the
regression that corresponds to the year. The variables are quint0
quint1 quint2 quint3 quint4 quint5 quint6 quint7 quint8 quint9, where
the last digit corresponds to the year. For example, quint0
corresponds to 2000 and quint9 corresponds to 2009. So I think I want
something like:
reg killed `varname' quint0 if startyear2==2000
Any idea on how to write this into a loop?
Thanks so much,
Linh
--
Linh Vuong
Master of Public Policy, Candidate 2012
Goldman School of Public Policy, UC Berkeley
[email protected] | @linh8u
http://www.linkedin.com/in/mlvuong
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/