You're absolutely right to focus on the suffix _ant rather than _anteil. The confusion earlier was due to the similarity in naming, but you're pointing out a very specific and valid issue.
Let’s clarify:
🔍 You asked:
In the last line kr_exp_var1'_var3'_ant is referred to, but I don't see where this is defined anywhere. For example: kr_exp_pub_ksa_ant, I don’t see anything with just the ending _ant.
And you’re correct — in the code provided, no variable ending in _ant is explicitly generated, yet it's used in this part:
But in the code you shared, that specific loop or command is missing.
🧠 Conclusion
Even though the code "runs" (as you said), there are two possibilities:
1. The variables were created earlier in the script
This is the most likely explanation.
Somewhere before the section you posted, there must be a nested loop like:
stata
foreach var1 in pub inst corp ret other {
foreach var3 in ksa irba {
gen delta_kr_exp_`var1'_`var3'_ant = kr_exp_`var1'_`var3'_anteil - l4.kr_exp_`var1'_`var3'_anteil
}
}
2. The code only runs conditionally or via another do-file
It’s possible these variables are generated in another included .do file or based on some conditional logic not visible here.
✅ What You Can Do Now
If you want to make the code fully self-contained and avoid errors, you should explicitly generate those missing variables. Add this somewhere before the decomposition section:
stata
foreach var1 in pub inst corp ret other {
if "`var1'" != "other" {
local var2 = "`var1'"
}
else {
local var2 = "rest"
}
foreach var3 in ksa irba {
gen delta_kr_exp_`var1'_`var3'_ant = kr_exp_`var1'_`var3'_anteil - L4.kr_exp_`var1'_`var3'_anteil
}
}
This will create all needed delta_kr_exp_*_*_ant variables, matching the usage in the rest of the code.
Let me know if you’d like help cleaning up or refactoring this entire block!