Announcement

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

  • Adding sum of coefficients to output table

    Dear all,

    I am estimating an equation of the form: xtreg y x1 i.year#x1 i.year, fe cluster(country)

    Where years are 2002, 2003, 2004, 2005

    In the latex output table I want to show the sum of the coefficients of i.year#x1 + x1. To calculate the total, I use:

    lincom 2002.year#x1 + x1
    lincom 2003.year#x1 + x1
    lincom 2004.year#x1 + x1
    lincom 2005.year#x1 + x1

    Is there any way that I can create a table showing the resulting coefficients from the lincom calculations including the statistical significance? I have tried with estadd / esttab but have not managed so far.

    Thank you very much!

    Joan

  • #2
    See https://www.statalist.org/forums/for...gression-table and the links therein.

    Comment


    • #3
      Thank you very much Andrew, this is very useful. I was wondering if there is a way so that it shows in the top part of the table instead of all the other coefficients?

      Best regards

      Comment


      • #4
        Let me provide some more details and clarifications:

        The baseline regression is as above (xtreg y x1 i.year#x1 i.year, fe cluster(country)) and I want to create a table with 5 columns, each new column adding a new set of control variables.

        For each column, I only want the coefficients of the impact of x1 on y (so, x1 + i.year#x1 i.year).

        Therefore ideally this would be a 4x5 table with each one of the 4 rows showing the lincom coefficient for a specific year in the 5 different equations. Below I would add the number of observations, R2 etc.

        Is this at all possible? Is there any other way that I could show this on latek?

        Thank you very much in advance,

        Joan



        Comment


        • #5
          If all the results to be combined are from lincom, then you just combine them in the same way as you combine regression results in esttab (SSC). Use margins with the post option. If you want specific code, present a reproducible example, e.g., using one of Stata's datasets.

          Code:
          webuse grunfeld, clear

          Comment


          • #6
            Thank you very much Andrew. Suppose that my regression is as follows:

            webuse grunfeld, clear
            xtreg mvalue c.invest#i.year c.invest i.year, fe

            How do I get a table that shows only the coefficients of c.invest + c.invest#i.year, and below the standard (no. observations, R2)?

            Thank you very much in advance,


            Joan

            Comment


            • #7
              Install Wouter Wakker's command xlincom from SSC, described in https://www.statalist.org/forums/for...-of-parameters, that does multiple linear combinations of parameters. For the statistics, hold these in a local macro following the panel regression.

              Code:
              webuse grunfeld, clear
              xtreg mvalue c.invest#i.year c.invest i.year, fe
              local r2=e(r2)
              local list
              forval y= 1936/ 1954{
                  local list "`list' (year`y'=invest+`y'.year)"
              }
              *ssc install xlincom
              xlincom `list', post
              estadd local r2= round(`r2', .001)
              esttab, stats(N r2, labels("Observations" "R-squared")) mlabel("Linear Combinations")
              Res.:

              Code:
              . esttab, stats(N r2, labels("Observations" "R-squared")) mlabel("Linear Combinations")
              
              ----------------------------
                                    (1)  
                           Linear Com~s  
              ----------------------------
              year1936            109.1  
                                 (1.04)  
              
              year1937            183.0  
                                 (1.73)  
              
              year1938            133.4  
                                 (1.24)  
              
              year1939            127.9  
                                 (1.21)  
              
              year1940            110.3  
                                 (1.05)  
              
              year1941            23.14  
                                 (0.22)  
              
              year1942            48.48  
                                 (0.46)  
              
              year1943            90.40  
                                 (0.86)  
              
              year1944            79.61  
                                 (0.76)  
              
              year1945            99.03  
                                 (0.93)  
              
              year1946            145.0  
                                 (1.37)  
              
              year1947            122.6  
                                 (1.14)  
              
              year1948            156.9  
                                 (1.45)  
              
              year1949            95.57  
                                 (0.90)  
              
              year1950            166.6  
                                 (1.58)  
              
              year1951            116.7  
                                 (1.09)  
              
              year1952            191.4  
                                 (1.79)  
              
              year1953            235.9*  
                                 (2.25)  
              
              year1954            369.6***
                                 (3.57)  
              ----------------------------
              Observations          200  
              R-squared            .767  
              ----------------------------
              t statistics in parentheses
              * p<0.05, ** p<0.01, *** p<0.001

              Comment


              • #8

                Thank you very much Andrew, this is super useful. If my regression has a loop of the form:

                forvalues i=1/2{
                if `i'==1 local sub="invest"
                if `i'==2 local sub="kstock"

                eststo eq1: xtreg mvalue c.`sub'#i.year `sub' i.year, fe

                local r2=e(r2)

                local list forval y= 1936/ 1954{

                local list "`list' (year`y'=`sub'+`y'.year#c.`sub')"

                }

                xlincom `list', post

                esttab [...]

                }

                I cannot figure out how to use "esttab" so that the coefficients from xlincom come up in the table, is there a way to do this? Thank you very much, Joan

                Comment


                • #9
                  May be simpler to name the model estimates using the interaction variable.

                  Code:
                  webuse grunfeld, clear
                  foreach var in invest kstock{
                      xtreg mvalue c.`var'#i.year c.`var' i.year, fe
                      local r2=e(r2)
                      local list
                      forval y= 1936/ 1954{
                          local list "`list' (year`y'=`var'+`y'.year#c.`var')"
                      }
                      xlincom `list', post
                      eststo `var'
                      estadd local r2= round(`r2', .001)
                  }
                  esttab invest kstock, stats(N r2, labels("Observations" "R-squared")) mlabel("invest" "kstock")
                  Res.:

                  Code:
                  . esttab invest kstock, stats(N r2, labels("Observations" "R-squared")) mlabel("invest" "ksto
                  > ck")
                  
                  --------------------------------------------
                                        (1)             (2)  
                                     invest          kstock  
                  --------------------------------------------
                  year1936            3.644***        0.640  
                                     (5.12)          (0.50)  
                  
                  year1937            4.647***        1.977  
                                     (7.79)          (1.65)  
                  
                  year1938            1.465          -0.323  
                                     (1.40)         (-0.35)  
                  
                  year1939            4.374***        0.725  
                                     (4.60)          (0.88)  
                  
                  year1940            3.740***        0.873  
                                     (5.78)          (1.03)  
                  
                  year1941            3.326***        1.029  
                                     (6.08)          (1.30)  
                  
                  year1942            1.893**        0.0509  
                                     (3.18)          (0.07)  
                  
                  year1943            2.586***        0.326  
                                     (4.22)          (0.47)  
                  
                  year1944            2.878***        0.173  
                                     (4.75)          (0.27)  
                  
                  year1945            3.551***        0.382  
                                     (5.88)          (0.62)  
                  
                  year1946            2.843***        0.610  
                                     (6.06)          (1.11)  
                  
                  year1947            1.390*         -0.427  
                                     (2.55)         (-1.06)  
                  
                  year1948            0.909          -0.733*  
                                     (1.70)         (-2.13)  
                  
                  year1949            1.593**        -0.377  
                                     (2.84)         (-1.20)  
                  
                  year1950            1.392**        -0.356  
                                     (2.81)         (-1.21)  
                  
                  year1951            2.461***        0.388  
                                     (6.08)          (1.43)  
                  
                  year1952            2.066***        0.447  
                                     (5.89)          (1.90)  
                  
                  year1953            2.329***        1.025***
                                     (9.15)          (5.39)  
                  
                  year1954            1.710***        0.598***
                                     (7.66)          (3.94)  
                  --------------------------------------------
                  Observations          200             200  
                  R-squared            .767             .55  
                  --------------------------------------------
                  t statistics in parentheses
                  * p<0.05, ** p<0.01, *** p<0.001
                  
                  .

                  Comment


                  • #10
                    Thank you very much Andrew. The problem is that I have 4 sets of equations because I add control variables in each equation, so it would look something like this:

                    forvalues i=1/2{
                    if `i'==1 local sub="invest"
                    if `i'==2 local sub="kstock"

                    eststo eq1: xtreg mvalue c.`sub'#i.year `sub' i.year, fe
                    local r2=e(r2)
                    local list forval y= 1936/ 1954{
                    local list "`list' (year`y'=`sub'+`y'.year#c.`sub')"
                    }
                    xlincom `list', post

                    eststo eq2: xtreg mvalue c.`sub'#i.year `sub' i.year control1, fe
                    local r2=e(r2)
                    local list forval y= 1936/ 1954{
                    local list "`list' (year`y'=`sub'+`y'.year#c.`sub')"
                    }
                    xlincom `list', post

                    eststo eq3: xtreg mvalue c.`sub'#i.year `sub' i.year control2, fe
                    local r2=e(r2)
                    local list forval y= 1936/ 1954{
                    local list "`list' (year`y'=`sub'+`y'.year#c.`sub')"
                    }
                    xlincom `list', post

                    eststo eq4: xtreg mvalue c.`sub'#i.year `sub' i.year control3, fe
                    local r2=e(r2)
                    local list forval y= 1936/ 1954{
                    local list "`list' (year`y'=`sub'+`y'.year#c.`sub')"
                    }
                    xlincom `list', post


                    esttab eq1 eq2 eq3 eq4 using table`sub'.tex, stats(N r2, labels("Observations" "R-squared")) mlabel("invest" "kstock") replace

                    so that it creates 2 tables (one for variable "invest" and one for variable "kstock", with each table 4 columns (eq1, eq2, eq3 and eq4) that show the coefficients of "invest" and "kstock" with the different control variables.

                    Is this possible?

                    Thank you very much again for all of your help.

                    Joan

                    Comment


                    • #11
                      I cannot follow what you are trying to do. Forget the loops and just show what commands you want to run, one at a time.

                      Comment


                      • #12
                        apologies for the confusion, here are the commands one at a time:

                        eststo eq1: xtreg mvalue c.invest#i.year invest i.year, fe
                        local r2=e(r2)
                        local list forval y= 1936/ 1954{
                        local list "`list' (year`y'=invest+`y'.year#c.invest)"
                        }
                        xlincom `list', post

                        eststo eq2: xtreg mvalue c.invest#i.year invest i.year control1, fe
                        local r2=e(r2)
                        local list forval y= 1936/ 1954{
                        local list "`list' (year`y'=invest+`y'.year#c.invest)"
                        }
                        xlincom `list', post

                        eststo eq3: xtreg mvalue c.invest#i.year invest i.year control2, fe
                        local r2=e(r2)
                        local list forval y= 1936/ 1954{
                        local list "`list' (year`y'=invest+`y'.year#c.invest)"
                        }
                        xlincom `list', post

                        eststo eq4: xtreg mvalue c.invest#i.year invest i.year control3, fe
                        local r2=e(r2)
                        local list forval y= 1936/ 1954{
                        local list "`list' (year`y'=invest+`y'.year#c.invest)"
                        }
                        xlincom `list', post

                        esttab eq1 eq2 eq3 eq4 using tableinvest.tex, stats(N r2, labels("Observations" "R-squared")) mlabel("invest" "kstock") replace


                        This is the first table, which has one column per equation, showing the coefficients with different control variables across columns. The second table is the same but substituting the variable "invest" for the variable "kstock".




                        Comment


                        • #13
                          You can add an additional outer loop to generate both tables, but here is some technique.

                          Code:
                          webuse grunfeld, clear
                          set seed 08062020
                          forval c=1/3{
                              gen control`c'= runiformint(0, `c'00)
                          }
                          local controls control1 control2 control3
                          eststo clear
                          forval c=0/ `=wordcount("`controls'")'{
                              local control=cond(`c'==0, "", word("`controls'", `c'))
                              xtreg mvalue c.invest#i.year c.invest i.year `control', fe
                              local r2=e(r2)
                              local list
                              forval y= 1936/ 1954{
                                  local list "`list' (year`y'=invest+`y'.year#c.invest)"
                              }
                              xlincom `list', post
                              eststo est`c'
                              estadd local r2= round(`r2', .001)
                          }
                          esttab est*, stats(N r2, labels("Observations" "R-squared")) mlabel(none)

                          Comment


                          • #14
                            Thank you very much Andrew. The control variables I have are not called control1, control2 and control3 but instead are 3 different sets of economic (gdpgrowth, inflation), demographic (agegroup, immigration) and sectorial (construcion, agriculture) controls. Is it possible to amend the commands above to accommodate for that?

                            Comment


                            • #15
                              Have you tried the code? I don't think that matters as your variable names are stored in a local named "controls". Maybe run the code line-by-line to try and understand what it does.

                              Comment

                              Working...
                              X