Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Referencing first non-omitted level of factor variable?

    I'm trying to put a title over a factor variable by using the refcat command of esttab. However, the first level of my variable is being ommitted due to collinearity in the regression, so when I try to use refcat(1.category "Category Title") , it does not know what 1.category is and omits the title altogether.

    My code is:

    Code:
    reghdfe y ib(last).pair_c ib(last).pair_c#grade , a(week)
    esttab using "out.tex", refcat(1.pair_c "Pair Type")
    Manually, in the above code, I can change 1.pair_c to 2.pair_c and it will work. However, is there a way I can dynamically have stata figure out the first non omitted level of pair_c?


  • #2
    Try this approach:
    Code:
    sysuse auto, clear
    
    //    CREATE A COLINEARITY INVOLVEING 1.rep78
    gen junk = 1.rep78
    
    regress price mpg i.junk ib(last).rep78
    
    matrix B = e(b)
    local bnames: colnames B
    display `"`bnames'"'
    
    //    FIND FIRST NON-OMITTED LEVEL OF rep78
    levelsof rep78, local(levels)
    foreach l of local levels {
        if `:list posof "`l'.rep78" in bnames' {
            local foundit `l'
            continue, break
        }
    }
    display `foundit'
    The logic is that omitted levels do not appear simply as #.varname in the column names of e(b), they appear as #o.varname or #b.varname. So loop over the levels of the variable of interest until you find one for which #.varname does appear in e(b)'s column names..

    Comment

    Working...
    X