Hello everyone,
I'm getting a weird error, -r(9611)-, when I run my program. Anyone
know what this is? I've seen two former posts about it, one saying
it's caused by no carriage return at the end of the file, which I
have, and the other saying it was caused by unbalanced braces, but
I've checked them and can't find a problem.
By putting pauses in various places, it seems that there is one block
that is causing the problem (code posted below, with the line I
suspect is causing the problem commented). However, when I comment out
that section, another block causes the same error (also posted below).
When I instead put the first code block in a -capture- block, a
different error is thrown somewhere in the SECOND code block:
- 0while already defined
- r(110);
I would really appreciate any help anyone could give me! I'm totally baffled.
Thanks,
Brian
*===============
*CODE BLOCK 1:
*===============
* Interact dummies if applicable
if "`interact'" != "nointeract" {
pause "In interact: `standard_dummies'"
* Cycle through each dummy to interact with (nonsub, Texas, etc.)
foreach dummy of varlist `standard_dummies' { //<-- ******* This is
where it causes the problem, I think
pause "`dummy' in first foreach loop"
* Cycle through each variable in the model to interact (e.g.
age/old, tenure/high_tenure, etc.)
foreach var of varlist `model_varlist' {
pause "`var' in second foreach loop"
* Create the label for the interaction term, using the labels from
each variable
local dummy_lab : variable label `dummy'
local var_lab : variable label `var'
if "`dummy_lab'" == "" local dummy_lab = "`dummy'"
if "`var_lab'" == "" local var_lab = "`var'"
local interact_label = "`dummy_lab' X `var_lab'"
* Note: the label is "Dummy X Variable", but the variable name is
"variable_X_dummy". This is so that, if we sort the variable list
alphabetically, we will group the interactions by variable.
local interact_var = substr("`var'",1,12) + "_X_" + substr("`dummy'",1,12)
* Generate variable
gen `interact_var' = `dummy' * `var'
* Add variable to the varlist
local model_varlist "`model_varlist' `interact_var'"
pause "End of `var' in second foreach loop"
}
}
}
*=============
*CODE BLOCK 2:
*=============
* Note that C_period is a local containing the name of the variable in
question, thus `C_period' is in fact a variable name
if "`dimensionality'" != "time_series" {
local period_fmt : format `C_period'
* NB: Check to see if we should noomit the period dummies, or omit
one other than the first period, perhaps a common period for all
companies
* Generate period dummies
xi i.`C_period', prefix(G_p_)
pause "After xi.period"
* Relabel period dummies
foreach var of varlist G_p_* { // <---- ****** If code block 1 above
is commented out or put in a -capture- block, the program runs until
this point, when the error is thrown
local label : variable label `var'
* xi labels the vars, eg: period==530, so get the "530" part
if regexm("`label'","^.*==([0-9]*)$") {
* If the period is formatted as a monthly variable, then label each
variable in a nice way
if strpos("`period_fmt'", "%tm") {
local newlab : display %tmMon._CCYY regexs(1)
}
* If the period has a value label, use that
else if "`: value label `var''" != "" {
local newlab : label (`var') `=regexs(1)'
if "`newlab'" == "" local newlab = "Period `=regexs(1)'"
}
* If the period has no convenient label, just use "Period #"
else {
local newlab = "Period `=regexs(1)'"
}
* Star the period of nonsubscription
if "`=regexs(1)'" != "" & "`=regexs(1)'" == "`C_nonsub_period'"
local newlab "`newlab'*"
label variable `var' "`newlab'"
}
}
pause "After xi.period relabel"
* Create local to store a list of period dummies
qui: ds G_p_*
local period_dummies "`r(varlist)'"
}
--
Brian Karfunkel
[email protected]
*
* 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/