Announcement

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

  • Replacing regression constant with control group mean in esttab

    I would like to replace the constant with control group mean when running a regression. Currently, through use of estout's stats() option, I can add it as part of the table's statistics, but what I would like to do is place it where the constant would normally be in the regression results table. My current sample code is:

    eg.
    reg x Treatment a b c

    sum x if Treatment == 0
    estadd scalar n1 = r(mean): est*
    esttab using "Test.csv", b(%4.2f) p star(* 0.10 ** 0.05 *** 0.01) stats(n1 N r2_a, fmt(%9.0f %9.0g %9.2f) labels ("Control Mean" "Obs" "Adjusted R-Squared")) nogap brackets label replace

    What this does is to place a line before displaying the options in stats, yet I would like the Control Mean to appear where Constant in the regression table would. Kindly advice.

    Thank you.
    Gerry

  • #2
    You can try applying the following 3 changes


    Code:
    reg x Treatment a b c
    sum x if Treatment == 0
    estadd scalar n1 = r(mean)
    
    esttab using "Test.csv", b(%4.2f) p star(* 0.10 ** 0.05 *** 0.01) \\
    stats(N r2_a, fmt(%9.0f %9.0g %9.2f)  labels ("Control Mean" "Obs" "Adjusted R-Squared"))\\
    nogap brackets drop(_cons) scalars(n1) label replace

    Comment


    • #3
      Thanks, Andrew. When I change the code as suggested, the Constant is indeed dropped, but it's not replaced by the Control Mean. When I run ereturn list, I actually see the scalar value n1 as part of the list, but it's not added to the bottom of the regression table. Any other tweaks to this?

      Comment


      • #4
        It seems this problem has not been fixed, see my previous workaround here

        https://www.statalist.org/forums/for...alar-pseudo-r2

        In your case, don't use estadd scalar but

        Code:
         reg x Treatment a b c
        sum x if Treatment == 0
        scalar n_1 = r(mean)
        eststo, addscalars(n1 n_1)  
        esttab using "Test.csv", b(%4.2f) p star(* 0.10 ** 0.05 *** 0.01) \\
        stats(n1 N r2_a, fmt(%9.0f %9.0g %9.2f) labels ("Control Mean" "Obs" "Adjusted R-Squared")) \\
        nogap brackets drop(_cons) scalars(n1) label replace
        Now, the value of n1 cannot appear where the constant term is because it is not a coefficient from the model but a scalar. You can include the plain option and add other options gradually if you want to eliminate separating lines between the coefficients and the other statistics.
        Last edited by Andrew Musau; 24 Aug 2017, 09:43.

        Comment


        • #5
          Hi Andrew, many thanks. This solved it.

          Comment


          • #6
            Just an update on why estadd does not work in #2 (what I wrongly thought was a bug). When specifying this command, you need to make sure that you first store estimates of the regression of interest. Then the workaround in #4 is not needed

            Code:
            eststo: reg x Treatment a b c sum x if Treatment == 0
            estadd scalar n1 = r(mean)  
            esttab using "Test.csv", b(%4.2f) p star(* 0.10 ** 0.05 *** 0.01) \\ \
            stats(n1 N r2_a, fmt(%9.0f %9.0g %9.2f)  labels ("Control Mean" "Obs" "Adjusted R-Squared"))\\
            nogap brackets drop(_cons) scalars(n1) label replace

            Comment


            • #7
              This was very helpful! Is there a way to display the same control mean across different models? One model with Fixed effect and another with no fixed effects which would have the same constant mean?

              Comment


              • #8
                The first time (model)

                Code:
                local n1= r(mean)
                estadd scalar n1 = `n1'
                and subsequently after each estimation, add

                Code:
                estadd scalar n1 = `n1'

                Comment

                Working...
                X