Hi all! I am using Stata 16.

I am having an issue with esttab. I am running several regressions, and want to include indicator variables in some models, and exclude them in others. An abbreviated version of my code reads:

Code:
 
foreach model of num 1/2 {
    if `model' == 1 {
        local hpi_var = "hpi"
    }
    else if `model' == 2 {
        local hpi_var = "i.REq5"
    }

        reg lhs cost `hpi_var' log_employment ///
            `census_controls' i.age_bucket i.risk_bucket, `vce'

        sum age if e(sample) == 1
        local mean = `r(mean)'
        estadd scalar sample_age `mean'
        sum riskscore if e(sample) == 1
        local mean = `r(mean)'
        estadd scalar sample_score `mean'
        eststo
   
}

esttab using "file.tex",  booktabs    ///
    cells(b(star fmt(`d')) se(par fmt(`d')))         ///
    eqlabels(none) starlevels("$^{*}$" 0.10 "$^{**}$" 0.05 "$^{***}$" 0.01)  ///
    indicate("HPI Quintiles = *REq5*" "Risk Bins = *risk_bucket*" "Age Bins = *age_bucket" "Census = `census_controls'")  ///
    stats(N r2 sample_age sample_score , layout(@ @ @ @) fmt(%12.0gc `d' %8.2f %8.2f) ///
    labels("Observations" "R-squared" "Instrument Magnitude" "Avg. Sample Age" "Avg. Sample Riskscore")) ///
    drop(_cons) compress label collabels(none) substitute(\_ _ No Yes)

Where REq5 is a variable of quintiles of hpi.

The issue is that esttab indicates "Yes" for both of the models in the "HPI Quintiles" indicator, even though the quintiles are only included in the second model.

Is there something I'm missing here? I've looked at the log file, and it's clear that the quintiles are only getting included in one of the regressions (so, it's not like they're accidentally being captured by "`census_controls'" or something).

Thank you in advance!