Announcement

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

  • Stacking hypothesis tests under regression results using the esttab command


    I have data which resembles the following:

    Code:
    clear
    input float(year y x lagx lag2x lag3x)
    1999 2  1  . . .
    2000 3  2  1 . .
    2001 2  1  2 1 .
    2002 3  3  1 2 1
    2003 3  2  3 1 2
    2004 2 43  2 3 1
    2005 1  1 43 2 3
    end
    Here, I have data for indepedent variables x, its first, second and third lag, and a dependent variable of interest, y. I wish to perform 2 sets of regressions, and hypothesis tests for each of these regressions, and then export the resultant output to LaTex using the est class of commands. In particular, what I wish to do is to have two individual columns, each corresponding to the following regressions: 1) y on x and lagx 2) y on x, lagx and lag2x. This is straightforward, and can be achieved using:
    Code:
      
     eststo: reg y x lagx eststo: reg y x lagx lag2x esttab using "table1.tex", scalar(F) varwidth(25) keep(x lagx lag2x) star(* 0.10 ** 0.05 *** 0.01) p  label replace
    Moreover, I would like to stack the results of these regressions under each of the columns of the regression they correspond to. In other words, I would like the results of the hypothesis test 1) to be stacked under column (1) and that of hypothesis test 2) to be stacked under column (2). Although the individual hypothesis tests are straightforward to perform, using the lincomtest command:

    Code:
     lincomest x+lagx lincomest x+lagx+lag2x
    I am not sure how to stack them under the original regression results using esttab. Any help or guidance on this is much appreciated.
    Last edited by Chinmay Sharma; 30 Mar 2020, 17:37.

  • #2
    Cross-posted at https://stackoverflow.com/questions/...sttab-in-stata

    Comment


    • #3

      @ Nick Cox - deleted.

      Comment


      • #4
        https://www.statalist.org/forums/help#crossposting explains our request, which is just that you tell us about cross-posting.

        Comment


        • #5
          OK, many thanks for clearing up the conflusion.

          Comment


          • #6
            You use -estadd-. I substituted -lincom- for -lincomest-, since I don't think you need -lincomest- in this situation.

            Code:
            clear all
            
            input float(year y x lagx lag2x lag3x)
            1999 2  1  . . .
            2000 3  2  1 . .
            2001 2  1  2 1 .
            2002 3  3  1 2 1
            2003 3  2  3 1 2
            2004 2 43  2 3 1
            2005 1  1 43 2 3
            end
            
            eststo: reg y x lagx
            lincom x+lagx
            estadd r(estimate)
            
            eststo: reg y x lagx lag2x
            lincom x+lagx+lag2x
            estadd r(estimate)
            
            esttab, scalar(F estimate) varwidth(25) keep(x lagx lag2x) star(* 0.10 ** 0.05 *** 0.01) p  label
            Additionally, you can simplify your data by using Stata's built-in time lag syntax if you -tsset- your data. Reference -help tsvarlist- for an explanation.

            Code:
            clear all
            
            input float(year y x)
            1999 2  1
            2000 3  2
            2001 2  1
            2002 3  3
            2003 3  2
            2004 2 43
            2005 1  1
            end
            
            tsset year
            
            eststo: reg y x L.x
            lincom x+L.x
            estadd r(estimate)
            
            eststo: reg y x L.x L2.x
            lincom x+L.x+L2.x
            estadd r(estimate)
            
            esttab, scalar(F estimate) varwidth(25) keep(x L.x L2.x) star(* 0.10 ** 0.05 *** 0.01) p  label
            I left out the LaTeX options for clarity, but you can add them back yourself.

            Comment


            • #7
              Nils Enevoldsen You are a life saver!!! Many thanks.

              Comment


              • #8
                Nils Enevoldsen Thanks a lot for your previous response. In your response, however, although I am able to obtain the null of the hypothesis that the sum of the coefficients equal 0, I am unable to reproduce the Standard Error of this difference, as well as the associated p-value from the t-test.

                After the lincom command, I am unable to save the p-value and the standard error. For instance, when I type

                Code:
                  
                 estadd r(estimate)
                I get the error scalar r(p) not found
                r(111);.

                Do you have any idea why this might be?

                Comment


                • #9
                  Code:
                  clear all
                  
                  input float(year y x)
                  1999 2  1
                  2000 3  2
                  2001 2  1
                  2002 3  3
                  2003 3  2
                  2004 2 43
                  2005 1  1
                  end
                  
                  tsset year
                  
                  eststo: reg y x L.x
                  lincom x+L.x
                  
                  // This shows the problem. The returned scalars are
                  // r(df), r(se), and r(estimate), but not r(p).
                  // Stata 15 and later apparently do return r(p).
                  return list
                  
                  // Therefore we have to calculate the r(p).
                  estadd r(estimate)
                  estadd scalar p = abs(2*ttail(r(df),abs(r(estimate)/r(se))))
                  
                  // And ditto for the second equation
                  eststo: reg y x L.x L2.x
                  lincom x+L.x+L2.x
                  estadd r(estimate)
                  estadd scalar p = abs(2*ttail(r(df),abs(r(estimate)/r(se))))
                  
                  esttab, scalar(F estimate p) varwidth(25) keep(x L.x L2.x) star(* 0.10 ** 0.05 *** 0.01) p  label

                  Comment


                  • #10
                    Nils Enevoldsen Thank you so much!!

                    Comment

                    Working...
                    X