Why does this code not overwrite the model on each loop?
Posted: Wed Oct 28, 2015 4:20 pm
This code
displays
On each iteration of the outer loop ("dofor model_name = ...") it should overwrite -full_model- and then iterate over the dependent variables in this model. Instead, it doesn't overwrite the model each time and keeps pulling the dependent variables from -full_model- as it was assigned on the first iteration of the outer loop. Is this something to do with the compiler?
If I swap "level" and "diff" in the declaration of the outer loop, the output is reversed:
so the error is still there.
Code: Select all
calendar(q) 1947 1
compute t0 = 1970:1
compute tT = 2002:4
open data "data.csv"
data(format = cdf, org = columns) /
close data
smpl t0 tT
declare string model_name
dofor model_name = "level" "diff"
if model_name == "level" {
system(model = full_model)
variables lgdpk lcdk
lags 1 to 4
deterministic fcm10c{1 to 4} constant
end(system)
}
else {
system(model = full_model)
variables dlgdpk dlcdk
lags 1 to 4
deterministic fcm10c{1 to 4} constant
end(system)
}
dofor dep_var = %modeldepvars(full_model)
compute eq = %modelfind(full_model, dep_var)
compute d = model_name + " " + %l(dep_var) + " maps to " + %l(%eqndepvar(eq)) + " with eq # " + eq
display d
end dofor dep_var
end dofor model_name
Code: Select all
level LGDPK maps to LGDPK with eq # 1
level LCDK maps to LCDK with eq # 2
diff DLGDPK maps to LGDPK with eq # 1
diff DLCDK maps to LCDK with eq # 2
If I swap "level" and "diff" in the declaration of the outer loop, the output is reversed:
Code: Select all
diff DLGDPK maps to DLGDPK with eq # 1
diff DLCDK maps to DLCDK with eq # 2
level LGDPK maps to DLGDPK with eq # 1
level LCDK maps to DLCDK with eq # 2