Announcement

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

  • Calculating the total of multiple regression estimates and standard errors, that are obtained from the same model

    Dear People,

    Is there a command in Stata to calculate the sum/average of several coefficients, and standard errors?
    The model I am analyzing is (sort of) the following:
    Click image for larger version

Name:	Formula.jpg
Views:	1
Size:	9.3 KB
ID:	1337395

    The output of this regression model contains three values for T (d = 3). Is there a way to take the average of the coefficients and the standard deviations?
    And is it possible to replace these averages with the regression estimates after that (for outreg2 purposes) ?

    I hope I made myself clear enough, if there are any furthers questions I am happy to elucidate.
    Thanks in advance,

    Jeroen

  • #2
    Please read FAQ 12 (http://www.statalist.org/forums/help) and follow its instructions. It will be possible to answer your questions only if you show us the Stata code you use to fit the model and the results, copied and pasted from the output window or log, between CODE delimiters.

    I don't understand what you mean by "replace these averages with the regression estimates after that", so illustrate by hand, if necessary (I don't use outreg2).
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      Dear Steve,

      To be more clear, I analyse the effect of coffeeshops on house prices.

      Code:
      set matsize 800
      set more off
      local coffeeshops coffeeshop1 coffeeshop2 coffeeshop3 //these represent observations (houses) that are located within 600 meter of an active coffeeshop (so the treatment group)
      //the distance of the three nearest coffeeshops are determined, if a coffeeshop is outside the range of 600 meter or not active, this dummy (coffeeshop1, coffeeshop2 or coffeeshop3) is 0.
      
      local Ai withinrange1 withinrange2 withinrange3 //indicate if the house is situated within a range of 600 meters of a (future) coffeeshop
      local housecharacteristics LNHouseSize nRooms nFloors Pool i.HouseSubType OpenPorch i.ParkFacility i.MaintenanceIn i.MaintenanceEx Monument ///
      CostsForSeller ConstrPer_1906_1930 ConstrPer_1931_1944 ConstrPer_1945_1959 ConstrPer_1960_1970 ConstrPer_1971_1980 ConstrPer_1981_1990 ///
      ConstrPer_1991_2000 ConstrPer_after2000 //represents Xi in the formula above
      
      regress LNPrice `coffeeshops' `housecharacteristics' i.Year i.Month
      
      //i.Year and i.Month represents period fixed effects
      The output of this regression is as follows:
      Number of obs = 646131
      Source SS df MS F(106,646024) = 19218.03
      Prob > F = 0.0000
      Model 169306.847 106 1597.23441 R-squared = 0.7592
      Residual 53691 .864646024 .083111253 Adj R-squared = 0.7592
      Total 222998 .711646130 .34512979 Root MSE = . 28829
      LNPrice Coef. Std. Err. t P>t [95% Conf. Interval]
      coffeeshop1 -.0004755 .0048719 -0.10 0.922 -.0100242 .0090733
      coffeeshop2 .0297427 .0056136 5.30 0.000 .0187403 .0407452
      coffeeshop3 .0424199 .007703 5.51 0.000 .0273223 .0575176
      withinrange1 -.0650802 .0049458 -13.16 0.000 -.0747739 -.0553866
      withinrange2 .0049671 .0060811 0.82 0.414 -.0069517 .016886
      withinrange3 -.0784532 .007826 -10.02 0.000 -.0937919 -.0631145
      LNHouseSize .6006385 .0015604 384.94 0.000 .5975803 .6036968
      nRooms .0268163 .0003644 73.60 0.000 .0261021 .0275304
      nFloors .0002785 .0007278 0.38 0.702 -.0011479 .0017049
      Pool .1728571 .009129 18.93 0.000 .1549645 .1907498
      Other Housing Characteristics +60 variables
      Period Fixed Effects 37 variables
      What I like to now is what the average coefficient is of the dummies coffeeshop1 - coffeeshop3, and its average standard error. And also for the withinrange1 - withinrange3 dummies.

      After that I use the following outreg2 code to make a nice word table. As you can see I used only coffeeshop1 and withinrange1. My second question is if I can replace the coffeeshop1 output variables (coefficient and standard error) with the average of the three variables, so that the table show the average, and not just one coffeeshop or all three coffeeshops.

      Code:
      outreg2 using Table3.doc, append ///
          ctitle(Housing, characteristics) dec(4) nocons noni nor2 noobs label ///
          keep(coffeeshop1 withinrange1 LNHouseSize nRooms nFloors Pool i.HouseSubType OpenPorch i.ParkFacility i.MaintenanceIn i.MaintenanceEx Monument ///
          CostsForSeller ConstrPer_1906_1930 ConstrPer_1931_1944 ConstrPer_1945_1959 ConstrPer_1960_1970 ConstrPer_1971_1980 ConstrPer_1981_1990 ///
          ConstrPer_1991_2000 ConstrPer_after2000) ///
          addtext(Housing Characteristics, Yes, Year fixed effects, Yes, PC4 fixed effects, No) ///
          addstat(Number of Observations, e(N), Adjusted R2, e(r2_a))
      Last edited by Jeroen Sanderink; 26 Apr 2016, 02:56.

      Comment


      • #4
        The correct formula for the above regression output is the following:

        Click image for larger version

Name:	Formula.jpg
Views:	1
Size:	9.4 KB
ID:	1337482

        Thanks in advance!

        Comment


        • #5
          Thanks for the code, but the FAQ asks that you show results between CODE delimiters too; notice that the table you gave doesn't have monospace font so that entries don't line up. Here's how to get the averages. I don't know outreg2 so I can't help with that part of your question.
          Code:
          scalar av_b  =  (_b[coffeeshop1] +   _b[coffeeshop2] + _b[coffeeshop3])/3
          scalar av_se = (_se[coffeeshop1] +_se[coffeeshop2] +_se[coffeeshop3])/3
          Steve Samuels
          Statistical Consulting
          [email protected]

          Stata 14.2

          Comment


          • #6
            Thanks for your feedback! I will try something with outreg2, if I succeed I will post it here!

            Comment


            • #7
              I found an answer to my second question, how to change the coefficient and standard error that are obtained from the regression. This can be used to include the calculated averages in the outreg2 output table.

              see below for the solution
              Code:
              //the below program change the coefficient of coffeeshop1 to the average of the three coffeeshops coefficients
              program changeb, eclass
                  tempname bmat
                  matrix `bmat' = e(b)
                  matrix `bmat'[1,1] = (_b[coffeeshop1] +   _b[coffeeshop2] + _b[coffeeshop3])/3 //_b[coffeeshop1] etc. are coefficient that are obtained from the regression (to show them type "matrix list e(b)")
                  ereturn repost b = `bmat'
              end
              
              //the below program change the standard error of coffeeshop1 to the average of the three coffeeshop standard errors
              program changese, eclass
                  tempname semat
                  matrix `semat' = e(V)
                  matrix `semat'[1,1] = ((_se[coffeeshop1] +_se[coffeeshop2] +_se[coffeeshop3])/3)*((_se[coffeeshop1] +_se[coffeeshop2] +_se[coffeeshop3])/3) (to show them type "matrix list e(V)")
                  ereturn repost V = `semat'
              end
              
              local coffeeshops coffeeshop1 coffeeshop2 coffeeshop3
              local Ai withinrange1 withinrange2 withinrange3
              regress LNPrice `coffeeshops' `Ai' i.Year i.Month
              
              //after the regression you just have to recall the programs
              changeb
              changese
              
              //
              outreg2 using Table3.doc, replace title("Table 3 - Name of table") ///
                  ctitle(Standard, DID) tdec(4) bdec(5) nocons noni nor2 noobs label ///
                  keep(coffeeshop1 withinrange1) //coffeeshop1 is now the average of the three coffeeshops
              You can write a similar program for other variables such as withinrange1 in this case

              Comment


              • #8
                Very nice! You can simplify a bit by ereturning b and V in one program
                Steve Samuels
                Statistical Consulting
                [email protected]

                Stata 14.2

                Comment

                Working...
                X