Why does RATS not recognize a series created in a loop?
Posted: Tue Sep 01, 2015 3:55 pm
This is a minimal working example of a larger code base I have. The code loops over two models, "a" and "b", and creates a placeholder variable for the dependent variable. This allows me to simply refer to "gdp_" or "cons_" in the code, instead of the specific series that varies depending on the model.
However, this code throws an error:
If I include the commented out portion
the code works properly. My intuition says that this happens because when RATS compiles the loop, it sees "gdp_", "cons_", etc. and can't determine that they're created dynamically in the program. Is this correct?
EDIT:
Furthermore, I actually tried simply declaring the series
but this also throws an error
so I think I'm either declaring the series wrong (most likely) or RATS actually needs values in the series for its compiler to recognize it.
Code: Select all
calendar(q) 1947 1
allocate 50 2015:2
smpl 1950:1 2000:1
open data nipa.csv
data(format=cdf, org=columns, dateform="m/d/y") 1947:1 2015:2 gdp cons gce gov unemp
close data
* compute logs
dofor s = gdp cons gce gov unemp
compute [label] lbl = "l" + %l(s)
set %s(lbl) = log(s{0})
compute [label] dlbl = "dl" + %l(s)
set %s(dlbl) = log(s{0}) - log(s{1})
end dofor s
/****
dofor s = gdp cons gce gov
compute [label] lbl_ = %l(s) + "_"
set %s(lbl_) = %na
end dofor s
****/
declare string model
dofor model = "a" "b"
dofor s = gdp cons gce gov
compute [label] lbl_ = %l(s) + "_"
if model == "a" {
compute [label] s_lbl = "L" + %l(s)
}
else if model == "b" {
compute [label] s_lbl = "DL" + %l(s)
}
set %s(lbl_) = %s(s_lbl)
labels %s(lbl_)
# s_lbl
end dofor s
dofor s = gdp_ cons_ gce_ gov_
linreg s
# unemp{1 to 4}
end dofor s
end dofor model
Code: Select all
(01.0389) dofor s = gdp_ <<<<
## SX11. Identifier GDP_ is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>Is it possible you meant
GDP
LGDP
If the name isn't mistyped, it's possible that you have a poorly formatted instruction
Common errors are
* a space before the ( in an option field
* a missing space before = in a SET or FRML
* a missing $ at the end of a long line which continues to the next
cons_ gce_ gov_
Code: Select all
dofor s = gdp cons gce gov
compute [label] lbl_ = %l(s) + "_"
set %s(lbl_) = %na
end dofor s
EDIT:
Furthermore, I actually tried simply declaring the series
Code: Select all
dofor s = gdp cons gce gov
compute [label] lbl_ = %l(s) + "_"
declare series %s(lbl_)
end dofor s
Code: Select all
(01.0113) declare series %s(## SX1. Identifier %S is Already in use as a(n) FUNCTION