I may have found the problem. In any case, the following code is wrong:
You cannot nest quoted material, "`c'" inside quoted material "if country != ...". When you try to do that, the result, when doing the non-aggregated iterations of your loops comes out to be something like -reghdfe ... if country == CAN"-, which is a syntax error because the " following the country code is unmatched. This has to do with the way quotes are handled in macros, but, more fundamentally, there is no context where you can correctly nest quotes inside quotes. The solution is simple, just remove the outer quotes, while preserving those around `c'. So:
Notice that this problem only arises in the non-aggregated analyses, which may indeed be why only your column 1 analysis survives. So, if there is nothing else wrong, this will likely resolve your problem.
A couple of thoughts:
Code:
loc regif "if country != "`c'"" loc ex_lab "Excluding, "`c'","
Code:
loc regif if country != "`c'" loc ex_lab Excluding, "`c'",
A couple of thoughts:
- In general, it is a bad idea to wrap the definition of a macro in quotes. They are usually not necessary, and, as you can see, they can sometimes mess things up badly. There are circumstances where you have to wrap the definition in quotes, and in that case, to be on the safe side you should always use Stata's compound double quotes, `" ... "', not ordinary quotes, " ... " for that purpose.
- If I am correctly understanding your code, these quote problems in the non-aggregated iterations should also have resulted in the -reghdfe- commands not being able to execute, and given the -capture- structure you used, you mus have gotten many "Unexpected regression error: ..." messages. Mentioning that would have been helpful in resolving this sooner. More broadly: -capture- structures are inherently dangerous because they suppress error notification. The structure you used that checks the value of c(rc) and branches to notify you of the unexpected errors mitigates this problem, but only if you pay attention to those error messages. If your code is correct and your data conforms to all necessary conditions for the code to work with it, you should not get any of those "Unexpected regression error" messages. Their presence signals that something important is wrong, and you should focus on fixing that before worrying that your output doesn't look right. Of course your output won't look right when the code itself is telling you that something is amiss! Error messages are your friends. Ignore them at your peril.
Comment