Announcement

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

  • Problem with esttab (factor) and estout (clear)

    I have questions about esttab/estout (Stata 17) that I could not fix myself, and I need advice from the community.

    Firstly, I have several variables that I would like to put into my regression. These variables measure different aspects but have the same concept. So, I defined the global variable and made a loop for my regression. Here is my code (the actual name of variables have been changed due to confidentiality)


    Code:
    global cons con_a con_b con_c con_d
    eststo clear
    foreach var of global cons {
        preserve
        rename (`var') (conduct)
        reg y conduct x c.x#c.conduct, r
        eststo `var'
        restore
    }
    esttab con_* using "${main_tex}/sample.tex", replace ///
        label booktabs nobaselevels interaction(" $\times$ ") b(4) ar2 nonumbers ///
        mtitles ("con_a" "con_b" "con_c" "con_d") ///
        title(This is a sample\label{tab1})
    I did the code like this because I want to show all four conditions on the same line, which (hopefully) makes it easier to compare across four conditions. Of course, this is not the only specification that I did. There were other specifications, and I used the same `esttab` command to generate the table.

    My questions are the following;
    1. At first, I used
      Code:
      esttab _all
      rather than
      Code:
      esttab con_
      . However, Stata exported more than four models in the report. It is definitely incorrect since the loop I wrote had only four variables. I checked
      Code:
      return list
      , and found that Stata stored more than four models in the memory. I ran
      Code:
      eststo clear
      , but it did not remove the model from the Stata's memory as `esttab _all` it still shows the same result (report more than four models). Did I use the right command to clear the memory in `eststo`?
    2. How can I check the models saved in the `eststo`?
    3. Since I changed the variable name to the conduct I had a problem when I reported the interaction term. To be exact, the interaction term (c.x and i.category = 1) is still in the table, and I cannot use label it to resolve this problem since I did not have this variable in the database. Note again that the conduct is generated only to align four conditions to be on the same line. I checked `esttab` the documentation, and it seems like label it is the only way the developers suggested. Is there another way to tackle this problem?

  • #2
    estout is from SSC (FAQ Advice #12).

    1. How can I check the models saved in the `eststo`?
    See

    Code:
    help estimates
    and in particular

    Code:
    estimates dir

    Did I use the right command to clear the memory in `eststo`?
    Yes. You could also use

    Code:
    estimates clear
    and this should clear all estimates in memory.


    1. Since I changed the variable name to the conduct I had a problem when I reported the interaction term. To be exact, the interaction term (c.x and i.category = 1) is still in the table, and I cannot use label it to resolve this problem since I did not have this variable in the database. Note again that the conduct is generated only to align four conditions to be on the same line. I checked `esttab` the documentation, and it seems like label it is the only way the developers suggested. Is there another way to tackle this problem?
    It is not clear what you are asking. If the goal is to change the name of the interaction term in the table, see the option -coeflabel()- in

    Code:
    help esttab

    Comment


    • #3
      Hi Andrew Musau,

      Thank you so much for your answer. I have tried your solution, but it does not work. Maybe I did not explain myself well enough in the first post. I did a reproducible example to show the exact problem I faced. My regression has the same dependent variable, but I want to run different variables (in this case, weight, length, and displacement; and align them on the same line). Here is the code:
      Code:
      sysuse auto, clear
      eststo clear
      
      label var turn "turn"
      global vars weight length displacement
      foreach var of global vars {
          preserve
          rename (`var') (newname)
          reg price newname turn c.turn#c.newname trunk, r
          eststo `var'
          restore
      }
      esttab _all, label mtitle(weight length displacement)
      
      --------------------------------------------------------------------
                                    (1)             (2)             (3)   
                                 weight          length    displacement   
      --------------------------------------------------------------------
      newname                    -4.218          -108.6          -64.10*  
                                (-1.40)         (-0.89)         (-2.45)   
      
      turn                      -1044.1***      -1212.0*         -554.4***
                                (-5.27)         (-2.09)         (-4.60)   
      
      turn # c.newname            0.210**         5.273           2.062** 
                                 (3.22)          (1.73)          (3.36)   
      
      Trunk space (.. ft.)       -57.16          -48.23           30.96   
                                (-0.71)         (-0.58)          (0.42)   
      
      Constant                  35331.9***      35548.5         23595.3***
                                 (5.01)          (1.62)          (5.12)   
      --------------------------------------------------------------------
      Observations                   74              74              74   
      --------------------------------------------------------------------
      The problem is at variable c.newname. I have been searching for ways to remove c. from the regression table. However, I have not found one. I tried labeling this variable in the loop, but it does not work since I restore the data before running another regression. Labeling this variable before looping does not work, too, since this variable does not exist in the database. I am not sure how I should tackle this problem. Do I have to find a new way to align the variable? Any suggestions or advice would be appreciated.

      Comment


      • #4
        As I said in #2, look at the -coeflabel()- option.

        Code:
        sysuse auto, clear
        eststo clear
        
        label var turn "turn"
        global vars weight length displacement
        foreach var of global vars {
            preserve
            rename (`var') (newname)
            reg price newname turn c.turn#c.newname trunk, r
            eststo `var'
            restore
        }
        esttab _all, label mtitle(weight length displacement) coeflabel(c.turn#c.newname turn#newname)
        Res.:

        Code:
        . esttab _all, label mtitle(weight length displacement) coeflabel(c.turn#c.newname turn#newname)
        
        --------------------------------------------------------------------
                                      (1)             (2)             (3)   
                                   weight          length    displacement   
        --------------------------------------------------------------------
        newname                    -4.218          -108.6          -64.10*  
                                  (-1.40)         (-0.89)         (-2.45)   
        
        turn                      -1044.1***      -1212.0*         -554.4***
                                  (-5.27)         (-2.09)         (-4.60)   
        
        turn#newname                0.210**         5.273           2.062** 
                                   (3.22)          (1.73)          (3.36)   
        
        Trunk space (.. ft.)       -57.16          -48.23           30.96   
                                  (-0.71)         (-0.58)          (0.42)   
        
        Constant                  35331.9***      35548.5         23595.3***
                                   (5.01)          (1.62)          (5.12)   
        --------------------------------------------------------------------
        Observations                   74              74              74   
        --------------------------------------------------------------------
        t statistics in parentheses
        * p<0.05, ** p<0.01, *** p<0.001

        Comment


        • #5
          Andrew Musau I really appreciate your answer and example code. You save me from this time-consuming problem. Thank you so much!

          Comment

          Working...
          X