Announcement

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

  • Drop and/or keep options using outreg and coefplot

    Hello,
    In my regressions I have a dummy variable for industry, but it is a control and I don't want to report it in my table of regressions using outreg. Example of my problem:

    Code:
    sysuse nlsw88.dta
    
    reg wage i.married i.industry
        est store ols_1
    
    outreg, clear
        est restore ols_1
            outreg using regressions, tex replace /*
                    */ drop(_cons i.industry) /*
                    */ ctitle("","Model #1") /*
                    */ nodisplay varlabels bdec(4) se starlevels(10 5 1) starloc(1) summstat(r2\rmse \ N) summtitle("R2"\"RMSE" \ "N")
    I get the following Stata error: "1b.industry" in drop() not found in estimates", as this is the base category but it still tries to drop anyway.
    A possible solution would be to write:

    Code:
    outreg, clear
        est restore ols_1
            outreg using regressions, tex replace /*
                    */ drop(_cons 2.industry 3.industry 4.industry 5.industry 6.industry 7.industry 8.industry 9.industry 10.industry 11.industry 12.industry) /*
                    */ ctitle("","Model #1") /*
                    */ nodisplay varlabels bdec(4) se starlevels(10 5 1) starloc(1) summstat(r2\rmse \ N) summtitle("R2"\"RMSE" \ "N")
    Which I'm trying to avoid, as in future regression I'll like to do this for a variable with 99 dummies.

    I also a similar problem using coefplot. For the same regression, I'm typing:

    Code:
    coefplot, vertical drop(_cons i.industry) yline(0)
    Which fails to remove the dummy coefficients for industry. Again, a solution that I don't like would be to write

    Code:
    coefplot, vertical drop(_cons 2.industry 3.industry 4.industry 5.industry 6.industry 7.industry 8.industry 9.industry 10.industry 11.industry 12.industry) yline(0)
    Does anyone have any suggestions?

    Thanks in advance!
    Hélder

  • #2
    Code:
    *.industry

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      *.industry
      Hi!
      I tried:
      Code:
      sysuse nlsw88.dta
      
      reg wage i.married i.industry
          est store ols_1
      
      outreg, clear
          est restore ols_1
              outreg using regressions, tex replace /*
                      */ drop(_cons *.industry) /*
                      */ ctitle("","Model #1") /*
                      */ nodisplay varlabels bdec(4) se starlevels(10 5 1) starloc(1) summstat(r2\rmse \ N) summtitle("R2"\"RMSE" \ "N")
      And I got the error: "variable *.industry not found
      in keep() or drop() option
      r(111);

      end of do-file".

      Did I do anything wrong?

      Comment


      • #4
        You are using the really old outreg command from SSC. Install outreg2 or esttab from SSC

        Code:
        ssc install outreg2
        Here, you can use drop(i.industry)

        If you have to use outreg, then use

        Code:
        keep()
        to specify what variables you want to keep. Unfortunately, the author of outreg does not maintain the command anymore but outreg2 provides essentially the same functionality and much more. The advice in #2 holds for coefplot which is also from SSC.

        Added in Edit: Also, since these dummies have the same names and consecutive numbering, you can do something like

        Code:
        local todrop ""
        forval i=2/12{
            local todrop `todrop' `i'.industry
        }
        di "`todrop'"
        Res.:

        Code:
        . di "`todrop'"
        2.industry 3.industry 4.industry 5.industry 6.industry 7.industry 8.industry 9.industry 10.industry 11.industry 12.industry
        Code:
        .   outreg using regressions, tex replace drop(_cons "`todrop'")
        
                                                                             ----------------------
                                                                                           wage   
                                                                             ----------------------
                                                                              1.married   -0.586  
                                                                                          (2.35)* 
                                                                              R2           0.07   
                                                                              N            2,232  
                                                                             ----------------------
                                                                               * p<0.05; ** p<0.01
        Last edited by Andrew Musau; 09 Dec 2019, 10:36.

        Comment


        • #5
          Thank you very much Andrew! I'm going with the loop as it also works for the coefplot. Using keep() also doesn't solve it as there are potentially dozens of dummies that I want to keep.

          I'm using outreg because my supervisor told me it was the best one. Me and him first used outreg2 a few years ago, then we used esttab and then he told me to switch back to outreg.

          Comment

          Working...
          X