Announcement

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

  • reg if dummy == 0; display whether dummy is 0 or 1 in esttab output

    Hello,
    Using code like
    Code:
    sysuse auto.dta, clear
    
    eststo: reg price mpg if foreign == 0
    eststo: reg price mpg if foreign == 1
    
    esttab * using stata_1_18.tex, replace
    I want to run regressions on a subsample, depending on whether a third variable is 0 or 1 (this variable is not included in the regression).

    Subsequently, using esttab, I want to display the results. Whether or not the dummy is 0 or 1 should be indicated in the output. It currently looks like this:
    Code:
    {
    
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
    
    \begin{tabular}{l*{2}{c}}
    
    \hline\hline
    
    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}\\
    
    &\multicolumn{1}{c}{price}&\multicolumn{1}{c}{price}\\
    
    \hline
    
    mpg & -329.3\sym{***}& -250.4\sym{**} \\
    
    & (-4.13) & (-3.64) \\
    
    [1em]
    
    \_cons & 12600.5\sym{***}& 12587.0\sym{***}\\
    
    & (7.76) & (7.15) \\
    
    \hline
    
    \(N\) & 52 & 22 \\
    
    \hline\hline
    
    \multicolumn{3}{l}{\footnotesize \textit{t} statistics in parentheses}\\
    
    \multicolumn{3}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
    
    \end{tabular}
    
    }
    And I would like to end up with a line such as
    Code:
    {
    
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
    
    \begin{tabular}{l*{2}{c}}
    
    \hline\hline
    
    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}\\
    
    &\multicolumn{1}{c}{price}&\multicolumn{1}{c}{price}\\
    
    \hline
    
    mpg & -329.3\sym{***}& -250.4\sym{**} \\
    
    & (-4.13) & (-3.64) \\
    
    [1em]
    
    \_cons & 12600.5\sym{***}& 12587.0\sym{***}\\
    
    & (7.76) & (7.15) \\
    
    \hline
    
    \(N\) & 52 & 22 \\
    
    foreign & 0 & 1 \\
    
    \hline\hline
    
    \multicolumn{3}{l}{\footnotesize \textit{t} statistics in parentheses}\\
    
    \multicolumn{3}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
    
    \end{tabular}
    
    }
    I looked into the indicate option, but it seems that this helps when we want to show if a variable is included, not whether the included dummy is 0 or 1.

    What is a way to achieve this? What alternatives are there to display the value of a dummy variable that defines the subsample elsewhere in the esttab output?
    Best,
    Max

  • #2
    Perhaps the addscalars and scalars options will do what you want.
    Code:
    sysuse auto.dta, clear
    
    eststo est1: reg price mpg if foreign == 0
    eststo est1, addscalars(foreign 0)
    eststo est2: reg price mpg if foreign == 1
    eststo est2, addscalars(foreign 1)
    
    esttab * using stata_1_18.tex, replace scalars(foreign)

    Comment


    • #3
      Thank you, that makes sense. I have successfully implemented it.
      Is it possible to do that in one line? And without having to give names to the estimates, which makes experimenting and shifting around the things a little messy.

      Comment


      • #4
        I'm not a user of estto and esttab, so I cannot answer your question from my knowledge.

        When I saw that your straightforward question, with a nice reproducible example included, had gone four hours without a response from a knowledgeable user, I decided it deserved some attempt at a response. I read the output of help estto and help esttab, did a little experimentation, and to avoid getting bogged down in debugging irrelevant syntax errors I encountered, chose the very basic approach I used to demonstrate that the two options do indeed provide a way of getting arbitrary numbers into the output table.

        If a knowledgeable user doesn't step up with an response to post #3, I suggest you follow a similar approach to improving the "proof of concept" my code provided.

        Comment


        • #5
          Still takes two lines, I think you can do it like this:

          Code:
          estimates clear
          sysuse auto.dta, clear
          eststo: reg price mpg if foreign == 0
          estadd local Domestic "Yes"
          eststo: reg price mpg if foreign == 1
          estadd local Domestic "No"
          esttab * using ols_table.tex, replace stats(Domestic)
          If you want in in one line, use model titles:

          Code:
          estimates clear
          sysuse auto.dta, clear 
          eststo, title("Domestic"): reg price mpg if foreign == 0
          eststo, title("Foreign"): reg price mpg if foreign == 1
          esttab * using ols_table.tex, replace mtitle
          Last edited by Dimitriy V. Masterov; 12 Jan 2018, 15:04.

          Comment

          Working...
          X