Announcement

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

  • Several regressions in one output table: Independent variables in rows, dependent in columns

    Dear all,

    I am trying to create a specific table from Stata output, and have tried to do so using esttab, estout, outreg2 and asdoc, but do not get the desired result. I have 11 y-variables, and regress them on the variable treatment and some other x-variables using a loop like this:

    local y_vars y1 y2 ...
    local x_vars x1 x2 ...

    local i = 1
    foreach var of local y_vars{
    qui probit `var' treatment `x_vars'
    estimates store m`i'
    local ++i


    Now, I would like to create a table where the variable treatment is the column header (other x-vars are irrelevant, just for control), and the 11 dependent variables feature in different rows. Ideally, I would like to add two further columns, where treatment is defined differently (see structure below).
    Treatment Treatment 2 Treatment3
    Dependent variables
    Y1
    Y2
    Y3 etc.

    After browsing on the forum, I used this code to create something remotely resembling what I want:

    esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11, keep(treatment) se nostar

    matrix C = r(coefs)
    eststo clear
    local rnames : rownames C
    local models : coleq C
    local models : list uniq models
    local i 0
    foreach name of local rnames {
    local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
    local ++j
    matrix tmp = C[`i', 2*`j'-1]
    if tmp[1,1]<. {
    matrix colnames tmp = `model'
    matrix b = nullmat(b), tmp
    matrix tmp[1,1] = C[`i', 2*`j']
    matrix se = nullmat(se), tmp
    }
    }
    ereturn post b
    quietly estadd matrix se
    }
    esttab using Test.doc, replace se starlevels(* 0.1 ** 0.05 *** 0.01) title("Probit regressions, binary dependent variables") mtitle("All provinces") modelwidth(30) varwidth(30) nogaps lines compress

    eststo clear



    However, this seems quite complicated and i don't know how to add further columns. Can you recommend a different way to do this? Which would be the most appropriate package to use?

    All help is much appreciated, please excuse the long post.

    Kind regards, Elisabeth

  • #2
    You should include a reproducible example if you want anything concrete. Not much use asking for how to work out something sufficiently complicated using an abstract example. Some tricks using esttab from SSC/ Stata Journal:

    1. Swap the name of the independent variable of interest and the dependent variable when running the regressions. The coefficient is the same and this allows you to have the name of the independent variable as the dependent variable in esttab.

    2. Stacking the results is a bit involved but doable.

    Presenting data and commands for two or three cases is enough to sketch a general solution.
    Last edited by Andrew Musau; 16 Oct 2019, 06:46.

    Comment


    • #3
      Thanks for your answer, I will first try to go with the first option and see if this can solve my issue.

      Comment


      • #4
        You can consider the wide option of asdoc.

        Code:
          sysuse auto
                
        asdoc reg price mpg rep78, replace wide
        
        * Add another regression where the dependent variable is trunk
        asdoc reg trunk mpg rep78, wide
        
        * Add third regression where the dependent variable is weight
        asdoc reg weight mpg rep78, wide
        Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	42.9 KB
ID:	1520799


        There are several useful options with wide option. Please read the help file, Section 4.3

        Code:
        help asdoc
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          You should include a reproducible example if you want anything concrete. Not much use asking for how to work out something sufficiently complicated using an abstract example. Some tricks using esttab from SSC/ Stata Journal:

          1. Swap the name of the independent variable of interest and the dependent variable when running the regressions. The coefficient is the same and this allows you to have the name of the independent variable as the dependent variable in esttab.

          2. Stacking the results is a bit involved but doable.

          Presenting data and commands for two or three cases is enough to sketch a general solution.
          Hi Andrew, what do you mean by swapping the dep and indep variables?

          Comment


          • #6
            Originally posted by roberto kimura View Post

            Hi Andrew, what do you mean by swapping the dep and indep variables?
            It means just that. Swap the variable names before running the regression.

            Code:
            sysuse auto, clear
            estimates clear
            foreach var in turn weight disp{
                *SWAP NAMES
                rename (mpg `var') (`var' mpg)
                eststo: regress `var' mpg, robust
                *REVERSE SWAP NAMES
                rename (mpg `var') (`var' mpg)
            }
            esttab est*, drop(_cons)
            Now you have the outcome on the row and the independent variables of interest on the columns.

            Res.:

            Code:
            . esttab est*, drop(_cons)
            
            ------------------------------------------------------------
                                  (1)             (2)             (3)   
                                 turn          weight            disp   
            ------------------------------------------------------------
            mpg                -0.946***     -0.00601***      -0.0445***
                              (-8.96)        (-10.29)         (-8.11)   
            ------------------------------------------------------------
            N                      74              74              74   
            ------------------------------------------------------------
            t statistics in parentheses
            * p<0.05, ** p<0.01, *** p<0.001

            Comment

            Working...
            X