Hi,
I am trying to create a nested loop to run a series of interactions in a regression command, an I have the following questions:
  1. I have tried the following command and receive the error “invalid vce”
local hetvar “prosociality intrinsic combined_motivation high_income pracdoc male”

foreach t of local hetvar {
eststo clear
foreach y of global treatment {
eststo, title("`y'"):reghdfe `y' nodrug_b nodrug_a `t’##(nodrug_b nodrug_a) if levelcode==2, vce(robust) absorb(diseasecode clinicid)
su `y' if nodrug_b==0 & nodrug_a==0 & e(sample)==1
estadd scalar conmean = `r(mean)'
}
}

However, on running it in the following format, it runs fine

eststo clear
foreach y of global treatment {
eststo, title("`y'"):reghdfe `y' nodrug_b nodrug_a prosociality##(nodrug_b nodrug_a) intrinsic##(nodrug_b nodrug_a)combined##(nodrug_b nodrug_a) ///
high_income##(nodrug_b nodrug_a) pracdoc##(nodrug_b nodrug_a) male##(nodrug_b nodrug_a) if levelcode==2, vce(robust) absorb(diseasecode clinicid)
su `y' if nodrug_b==0 & nodrug_a==0 & e(sample)==1
estadd scalar conmean = `r(mean)'
}

Could you please tell me why this is happening? And how can I generate a nested loop where each term in the local "hetvar" with the variables "nodrug_b" "nodrug_a" in separate regressions.

2. When outputting using esttab and the following commands, while it appears to run fine, there is no output file generated. How can I generate an output file for this?

esttab using "$path/Output/Motivation/treat_motivation_thc.csv", b(%9.3fc) se(%9.3fc) ///
starlevels( * 0.1 ** 0.05 *** 0.01) ar2(2) keep(nodrug_b nodrug_a 1.prosociality##(1.nodrug_b 1.nodrug_a)) intrinsic##(nodrug_b nodrug_a) ///
combined##(nodrug_b nodrug_a) high_income##(nodrug_b nodrug_a) pracdoc##(nodrug_b nodrug_a) ///

3. Is there anyway for me to keep only the valid interaction terms in the output file, i.e. 1.prosociality#1.nodrug_a. And how can I label these interaction terms in the output file?

Many thanks,
Karishma