Announcement

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

  • Keeping only selected variables in -esttab- output.

    I am running the following analysis in Stata 14.

    Code:
    quietly mlogit   bmi   i.age  i.smoke   i.beef   i.chicken   if sex=1
     eststo a
     
    
    quietly mlogit     bmi  i.age    i.smoke   i.beef   i.chicken   if sex=2
    eststo b
    
    
    quietly esttab a b, ci  ar2  eform
    
    esttab using BMI.rtf, ci r2  eform
    Is it possible to keep only selected variables in esttab, as I want the output only for i.age and i.smoke.

  • #2
    Code:
    esttab a b, ci ar2 eform keep(age smoke)
    esttab a b, ci ar2 eform drop(beef chicken)
    Both are equivalent in this example.
    Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

    When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

    Comment


    • #3
      Originally posted by Weiwen Ng View Post
      Code:
      esttab a b, ci ar2 eform keep(age smoke)
      esttab a b, ci ar2 eform drop(beef chicken)
      Both are equivalent in this example.
      Thanks a lot Weiwen. The drop function is working for me. Just installed dataex.

      Comment


      • #4
        Dear members,
        I have a similar problem, but for a categorical variable Stata tells me that the "coefficient 'categorical variable' not found".
        I used the following code with the -estout- program by Ben Jann:
        Code:
        global xlist1 sales mtb i.industry i.year
        eststo clear
        foreach var of varlist $ylist {
         eststo: xtreg `var' $xlist1
        }
        esttab using almeidare.rtf, ci eform drop(industry year) ///
         label scalars(r2_o) onecell nogap modelwidth(10) replace
        where industry and year both appear in the global macro xlist1 as categorical variables. This however gives me the error message mentioned above, also if I specify the
        Code:
         drop(i.industry i.year)
        in the -esttab- command

        How can I drop the two categorical variables in the export/output?

        Comment


        • #5
          I think the problem is that you re not referring to the estimated coefficient/variable with the name that Stata has assigned to it. I.e., Stata does not accept the syntax -drop(i.industry)-.

          Code:
          . set obs 10
          number of observations (_N) was 0, now 10
          
          . gen dummy = 1
          
          . replace dummy =2 in 5/l
          (6 real changes made)
          
          . gen y = rnormal()
          
          . gen x = rnormal()
          
          . reg y x i.dummy
          
                Source |       SS           df       MS      Number of obs   =        10
          -------------+----------------------------------   F(2, 7)         =      0.60
                 Model |  .362903293         2  .181451647   Prob > F        =    0.5768
              Residual |  2.13151275         7  .304501822   R-squared       =    0.1455
          -------------+----------------------------------   Adj R-squared   =   -0.0987
                 Total |  2.49441605         9  .277157339   Root MSE        =    .55182
          
          ------------------------------------------------------------------------------
                     y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                     x |   .0331587   .1742146     0.19   0.854    -.3787933    .4451106
               2.dummy |   .3865997   .3567258     1.08   0.314    -.4569229    1.230122
                 _cons |  -.2498393   .2893364    -0.86   0.416    -.9340112    .4343326
          ------------------------------------------------------------------------------
          
          . esttab, drop(2.dummy)
          
          ----------------------------
                                (1)   
                                  y   
          ----------------------------
          x                  0.0332   
                             (0.19)   
          
          1.dummy                 0   
                                (.)   
          
          _cons              -0.250   
                            (-0.86)   
          ----------------------------
          N                      10   
          ----------------------------
          t statistics in parentheses
          * p<0.05, ** p<0.01, *** p<0.001
          
          . esttab, drop(1.dummy 2.dummy)
          
          ----------------------------
                                (1)   
                                  y   
          ----------------------------
          x                  0.0332   
                             (0.19)   
          
          _cons              -0.250   
                            (-0.86)   
          ----------------------------
          N                      10   
          ----------------------------
          t statistics in parentheses
          * p<0.05, ** p<0.01, *** p<0.001
          
          .

          Comment


          • #6
            You are right, thanks a lot!

            Comment


            • #7
              And in related good news, it seems that Stata accepts wildcards, so you do not need to explicitly refer to the variables you want to drop. (Which will be a pain if you have many industries.)

              Code:
              . esttab, drop(*.dummy)
              
              ----------------------------
                                    (1)   
                                      y   
              ----------------------------
              x                  0.0332   
                                 (0.19)   
              
              _cons              -0.250   
                                (-0.86)   
              ----------------------------
              N                      10   
              ----------------------------
              t statistics in parentheses
              * p<0.05, ** p<0.01, *** p<0.001

              Comment


              • #8
                Originally posted by Joro Kolev View Post
                And in related good news, it seems that Stata accepts wildcards, so you do not need to explicitly refer to the variables you want to drop. (Which will be a pain if you have many industries.)

                Code:
                . esttab, drop(*.dummy)
                
                ----------------------------
                (1)
                y
                ----------------------------
                x 0.0332
                (0.19)
                
                _cons -0.250
                (-0.86)
                ----------------------------
                N 10
                ----------------------------
                t statistics in parentheses
                * p<0.05, ** p<0.01, *** p<0.001
                Thanks for the code!

                Comment


                • #9
                  I am running into a problem with this specific pain. How do I find out what stata called the variable?
                  I have a variable called "party_withmiss" and in the regression I use it as i.party_withmiss. I do not want this data in my estout regression output but I can't figure out how to drop the categorical variables. So how do I see what stata called the variables? I could do it with some of the labels by using shorthand of the label (like CDU*) - but that didn't work for all of the categories within the variable. Is there a rule of thumb?

                  Comment


                  • #10
                    Most estimation commands have an option -coeflegend- that allows you to see how coefficients are named, e.g.,

                    Code:
                    xtreg y x1 ... xn, fe robust coeflegend
                    Usually, factor variables have the format #.varname, where "#" is a numerical value representing the level. Therefore, for "i.party_withmiss", you'd need

                    Code:
                    drop(*.party_withmiss)

                    Comment

                    Working...
                    X