Announcement

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

  • Esttab - keeping only some coefficients

    Dear all, I am struggling with the following issue: I would like to put in table the results of a number of models, but I am interested in having in the table only the coefficients for some selected categories of just one variable I include in my model (in my case, categories 4 and 5 of the variable car_groups).

    I think I should exploit the option -keep-, but whit the following command:

    Code:
    reg city i.car_groups if region == 1
    estimates store m1
     esttab m1 using "",    cells("b ci_l ci_u")  replace  keep(car_groups)
     
    reg city i.car_groups  i.age if region == 1
      estimates store m2
     esttab m2 using "",   cells("b ci_l ci_u")  append keep(car_groups)
    I receive the error:

    Code:
    coefficient car_groups not found
    Do you have any clue on why? In the regression table the coefficients associated to the different categories of the variable car_groups are indeed estimated and shown...

    here my data

    Code:
    clear
    input float(city car_groups) int age float region
    0 1 51 3
    1 1 40 3
    1 1 61 3
    0 1 62 3
    0 3 47 3
    0 3 46 3
    0 1 19 3
    1 3 58 3
    0 1 58 3
    0 5 46 3
    end
    label values car_groups car_groups
    label def car_groups 1 "a", modify
    label def car_groups 3 "c", modify
    label def car_groups 5 "e", modify
    label values age age_VL
    label values region region

    Any help would be really appreciated.

    Best, Giorgio Piccitto

  • #2
    estout is from SSC, as you are asked to explain (FAQ Advice #12). The coefficients of factor variables start with numbers, so you cannot simply specify the name of the categorical variable. However, to capture all of them, you can use an asterisk as a wildcard character.

    Code:
    esttab ..., keep(*car_groups)
    Last edited by Andrew Musau; 06 Jul 2024, 04:34.

    Comment


    • #3
      Dear Andrew Musau , thanks a lot for your tip.

      I tried:

      Code:
      reg city i.car_groups if region == 1
      estimates store m1
       esttab m1 using "",    cells("b ci_l ci_u")  replace   keep(2*car_groups 3*car_groups)
       
      reg city i.car_groups  i.age if region == 1
        estimates store m2
       esttab m2 using "",   cells("b ci_l ci_u")  append  keep(2*car_groups 3*car_groups)
      And the result seems fine to me.

      I would like to ask an additional question: how could I repeat the same operation in combination with the command margins? I have the following model:

      Code:
      reg city i.car_groups##i.male if region == 1
       margins car_groups##male, post
      estimates store A
       esttab A using "",    cells("b ci_l ci_u")  replace   keep(1._predict)
      and I obtain the followin output with margin

      Code:
      ---------------------------------------------------------------------------------
                      |            Delta-method
                      |     Margin   std. err.      t    P>|t|     [95% conf. interval]
      ----------------+----------------------------------------------------------------
           car_groups |
                   a  |   .2919808   .0010933   267.07   0.000      .289838    .2941236
                   b  |   .3915986    .003469   112.88   0.000     .3847994    .3983978
                   c  |   .2153038   .0032303    66.65   0.000     .2089724    .2216352
                   d  |   .1794251   .0082902    21.64   0.000     .1631765    .1956736
                   e  |   .2615537   .0037627    69.51   0.000      .254179    .2689284
                   f  |   .3671427   .0236609    15.52   0.000     .3207681    .4135174
                      |
                 male |
                   0  |   .2834819   .0013355   212.27   0.000     .2808644    .2860994
                   1  |   .2958903   .0013585   217.80   0.000     .2932277     .298553
                      |
      car_groups#male |
                 a#0  |   .2823884   .0015413   183.22   0.000     .2793675    .2854092
                 a#1  |   .3019048   .0015508   194.67   0.000     .2988652    .3049444
                 b#0  |   .3849489    .004591    83.85   0.000     .3759507    .3939471
                 b#1  |   .3984782   .0052207    76.33   0.000     .3882457    .4087106
                 c#0  |    .226731   .0044844    50.56   0.000     .2179418    .2355203
                 c#1  |   .2034816   .0046553    43.71   0.000     .1943573    .2126059
                 d#0  |   .1744966   .0123391    14.14   0.000     .1503123     .198681
                 d#1  |   .1845238   .0110241    16.74   0.000     .1629168    .2061308
                 e#0  |   .2737377   .0052929    51.72   0.000     .2633637    .2841116
                 e#1  |   .2489487   .0053497    46.53   0.000     .2384634     .259434
                 f#0  |   .3502538   .0321933    10.88   0.000     .2871557    .4133519
                 f#1  |   .3846154    .034758    11.07   0.000     .3164905    .4527403
      ---------------------------------------------------------------------------------
      I would like to have on the table the average predictions only the first two coefficients of my interaction term (a#0 and a#1, namely .2823884 and .3019048).

      What should I specify on
      Code:
       keep
      ? The specification
      Code:
       keep(1._predict)
      indeed gives me an error.


      Thanks really a lot for your support.

      Best GP

      Comment


      • #4
        Use the -coeflegend- option of margins to see how the coefficients are named.

        Code:
        margins car_groups##male, post coeflegend
        From what I see of the margins table that you posted, the categorical variable name is still maintained.

        Comment


        • #5
          Dear Andrew Musau , thanks.

          With the
          Code:
           coeflegend
          option, I can see the following table:

          Code:
               car_groups |
                       a  |   .2919808  _b[1bn.car_groups]
                       b  |   .3915986  _b[2.car_groups]
                       c  |   .2153038  _b[3.car_groups]
                       d  |   .1794251  _b[4.car_groups]
                       e  |   .2615537  _b[5.car_groups]
                       f  |   .3671427  _b[6.car_groups]
                          |
                     male |
                       0  |   .2834819  _b[0bn.male]
                       1  |   .2958903  _b[1.male]
                          |
          car_groups#male |
                     a#0  |   .2823884  _b[1bn.car_groups#0bn.male]
                     a#1  |   .3019048  _b[1bn.car_groups#1.male]
                     b#0  |   .3849489  _b[2.car_groups#0bn.male]
                     b#1  |   .3984782  _b[2.car_groups#1.male]
                     c#0  |    .226731  _b[3.car_groups#0bn.male]
                     c#1  |   .2034816  _b[3.car_groups#1.male]
                     d#0  |   .1744966  _b[4.car_groups#0bn.male]
                     d#1  |   .1845238  _b[4.car_groups#1.male]
                     e#0  |   .2737377  _b[5.car_groups#0bn.male]
                     e#1  |   .2489487  _b[5.car_groups#1.male]
                     f#0  |   .3502538  _b[6.car_groups#0bn.male]
                     f#1  |   .3846154  _b[6.car_groups#1.male]
          So, as far as I got, I need to specify in my
          Code:
           keep
          the coefficients
          Code:
           _b[1bn.car_groups#0bn.male]
          and
          Code:
           _b[1bn.car_groups#1.male]
          , is that right?

          Anyway, when running:

          Code:
          reg city i.car_groups##i.male if region == 1
           margins car_groups##male, post coeflegend
          estimates store A
           esttab A using "",    cells("b ci_l ci_u")  replace   keep(1bn.car_groups#0bn.male)
          I receive the error
          Code:
           coefficient 1bn.car_groups#0bn.male not found
          What did I do wrongly?

          Thanks really for your priceless support. Best, GP

          Comment


          • #6
            Code:
            keep(1*cargroups#0*male) baselevels

            Comment


            • #7
              Dear Andrew Musau, thanks a lot, this perfectly work.

              Just a small add-on: I noticed that including or not the specification
              Code:
               baseleves
              does not alter the average predtictions (they remain exactly the same), why did you include it? In which cases this specification must be included?

              Thanks really a lot, Giorgio

              Comment


              • #8
                Actually, that is the default to keep base levels of factor variables, so you can ignore it. From the documentation, non-default option is

                nobaselevels drops base levels of factor variables (only relevant in Stata 11 or newer).

                Comment


                • #9
                  Ok, so basically baselevels is already specified by default from Stata.

                  Thanks really a lot Andrew, have a nice weekend.

                  Best, Giorgio

                  Comment


                  • #10
                    Dear Andrew Musau and everyone, I have a follow up on the above question.

                    I would like to keep some average marginal effects at predicted values of one variable (included in interaction, as you could see below), but I can't find out to write this option in Stata (as I did, I receive an error).

                    May you provide me some support?

                    Thanks a lot, Giorgio Piccitto

                    Here the data
                    Code:
                    * Example generated by -dataex-. For more info, type help dataex
                    clear
                    input float(score type_house edu_high)
                    25.04 1 0
                    25.94 1 0
                    43.85 1 0
                    25.49 1 0
                    50.57 1 0
                        . 1 0
                        . 1 0
                        . 1 0
                    39.02 1 1
                    73.91 1 1
                    end
                    label values type_house type_house
                    label def type_house 1 "a", modify

                    Here the output

                    Code:
                    reg score i.type_house##i.edu_high 
                    margins, dydx(type_house) at(edu_high=(0(1)1)) post coeflegend
                    estimates store hetedu1
                    
                    esttab hetedu1 using "C:\...\hetedu.rtf",    cells("b ci_l ci_u")  append   keep(5*type_house_at1*edu_high)
                    I receive the following error:

                    Code:
                    coefficient 5*type_house_at1*edu_high not found
                    Thanks really a lot, best, GP

                    Comment


                    • #11
                      Code:
                      esttab, keep(1.type_house:1._at)
                      or with only a single equation as you have

                      Code:
                      esttab, keep(1._at)

                      Comment


                      • #12
                        Dear Andrew Musau, thanks really a lot, it perfectly works.

                        Have a nice evening, best, Giorgio

                        Comment


                        • #13
                          Dear Andrew Musau , sorry if I come back to you with an additional question.

                          I am trying to estimate the following model asking for the 90% (instead of standard 95%) confidence intervals:

                          Code:
                          reg c73    i.esse##i.year  , level(90)   
                          margins, dydx(year) at(esse=(0(1)1)) post   level(90) 
                          estimates store Adydx 
                          esttab Adydx using "...",    cells("b ci_l ci_u")  append   keep(6*year:1._at 6*year:2._at)  baselevels
                          Anyway, the table created still gives me the 95% c.i., am I wrongly specificed something? The results of reg and margins are correctly provided with 90% c.i.

                          Thanks a lot, Giorgio

                          Comment


                          • #14
                            esttab by default outputs 95% CIs. You need to add the option

                            Code:
                            level(90)
                            for 90% CIs.

                            Comment


                            • #15
                              Dear Andrew, thanks a lot, I mistakenly tried to add this option to -estimates- and not to -esttab-, now it perfectly works.

                              Best and thanks, Giorgio

                              Comment

                              Working...
                              X