Announcement

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

  • Tables: Using eststo, esttab & globals for contral vars

    Dear Statalist - Community,

    in my analysis I have several sets of control variables specified as globals and have created output tables successively integrating these globals.

    My problem is that I would like to indicate in my tables which groups of control variables are in the model. I tried the "indicate()" add of the esttab command - described here: http://repec.org/bocode/e/estout/adv...ml#advanced006. But this does not work with my globals defined.

    Please notice the following very simplified example of my code:

    Code:
    eststo a: reg y x $control1
    eststo b: reg y x $control1 $control2
    eststo c: reg y x $control1 $control2 $control3
    
    local varlist x $control1 $control2 $control3
    
    esttab a b c, indicate("control1 = $control1" "control2 = $control2" " control3 = $control3" )
    Thanks for your support in advance!

    Warm regards,
    Bianca

  • #2
    But this does not work with my globals defined.
    See Clyde Schechter's post #2 on the dangers of using globals. How many times previously have you defined a global named "control1"? I would suggest that you use locals for such purposes. Otherwise, there does not appear to be anything wrong with your code.

    Code:
    sysuse auto, clear
    local control1 headroom trunk
    local control2 length turn
    local control3 displacement gear_ratio
    eststo a: regress mpg weight `control1'
    eststo b: regress mpg weight `control1' `control2'
    eststo c: regress mpg weight `control1' `control2' `control3'
    esttab a b c, indicate("Controls 1=`control1'" "Controls 2=`control2'"  "Controls 3=`control3'")
    Res.:

    Code:
    . esttab a b c, indicate("Controls 1=`control1'" "Controls 2=`control2'"  "Controls 3=`control3'")
    
    ------------------------------------------------------------
                          (1)             (2)             (3)   
                          mpg             mpg             mpg   
    ------------------------------------------------------------
    weight           -0.00565***     -0.00375*       -0.00420*  
                      (-7.98)         (-2.24)         (-2.03)   
    
    _cons               39.68***        48.25***        45.80***
                      (21.98)          (6.81)          (4.83)   
    
    Controls 1            Yes             Yes             Yes   
    
    Controls 2             No             Yes             Yes   
    
    Controls 3             No              No             Yes   
    ------------------------------------------------------------
    N                      74              74              74   
    ------------------------------------------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001

    Comment


    • #3
      Dear Andrew,

      thank you very much - using "locals" instead of "globals" worked.

      Now my next problem is that in my locals defined I have categorical variables with the prefix i. If I include them in the command, the" indicate" option does not work anymore.

      By any change, do you know a solution to that problem as well?

      Thank you so much for your help in advance!

      Warm regards,
      Bianca

      Comment


      • #4
        Multiple ways to address this. I would keep the structure of the locals as is and address this in the esttab command line. The rationale is that factor variables indicated by "i.catvar" are named 1.catvar, 2.catvar, and so on. All of these are captured by the wildcard syntax "*.catvar". So we can just replace i.catvar with *.catvar. Example:

        Code:
        sysuse auto, clear
        local control1 headroom trunk
        local control2 length i.rep78
        local control3 displacement gear_ratio
        eststo a: regress mpg weight `control1'
        eststo b: regress mpg weight `control1' `control2'
        eststo c: regress mpg weight `control1' `control2' `control3'
        esttab a b c, indicate("Controls 1=`control1'" "Controls 2= `=ustrregexra("`control2'", "i.", "*.",.)'" "Controls 3=`control3'")
        You can indicate all the controls as highlighted, even if there does not exist a factor variable in the variable list defined by the local. In this case, the code has no effect, but it saves you the time of trying to figure out which variable lists include factor variables.

        Res.:

        Code:
        . esttab a b c, indicate("Controls 1=`control1'" "Controls 2= `=ustrregexra("`control2'", "i.", "*.",.)'" "Cont
        > rols 3=`control3'")
        
        ------------------------------------------------------------
                              (1)             (2)             (3)   
                              mpg             mpg             mpg   
        ------------------------------------------------------------
        weight           -0.00565***     -0.00226        -0.00230   
                          (-7.98)         (-1.28)         (-0.93)   
        
        _cons               39.68***        50.31***        43.76***
                          (21.98)          (6.53)          (4.43)   
        
        Controls 1            Yes             Yes             Yes   
        
        Controls 2             No             Yes             Yes   
        
        Controls 3             No              No             Yes   
        ------------------------------------------------------------
        N                      74              69              69   
        ------------------------------------------------------------
        t statistics in parentheses
        * p<0.05, ** p<0.01, *** p<0.001

        Comment


        • #5
          Thank you very much, Andrew!

          For some reasons, "ustrregexra" replaced an "i" within variable names of non-categorical control variables. That's somehow strange because in your command you specified that only "i." should be replaced and not "i" without a "." following.

          Anyhow, I used "subinstr" instead of "ustrregexra" following your logic and now everythink is fine. Warm greetings from Germany!

          Comment


          • #6
            Sorry, the period is a wildcard in regular expressions, which should be escaped. Glad that you figured out a way using -subinstr()-. For completeness, here is how you specify the condition.

            Code:
            local controls price initial weight i.rep78 foreign
            di "`=ustrregexra("`controls'", "i\.", "*.",.)'
            Res.:

            Code:
            . local controls price initial weight i.rep78 foreign
            
            . 
            . di "`=ustrregexra("`controls'", "i\.", "*.",.)'
            price initial weight *.rep78 foreign

            Comment

            Working...
            X