Announcement

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

  • esttab: mean & standard error of mean by two groups - grouping and labelling columns

    Hey everyone,

    I generated a table that shows the mean and standard error of the mean for different variables by groups.
    I used esttab from SSC in Stata 18.0, but I'm not sure it is the right choice in this context.

    This is my (simplified) data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(treatment north expats_error expats_or1_error expats_or2_error)
    0 0 20.14  4.82 3.58
    0 0 30.14  2.82 6.58
    1 0  8.14  4.82 2.58
    0 1 23.14  1.82 8.58
    0 1 15.13 29.82 6.58
    0 1  4.13   .82 -.41
    1 1 66.13  1.82 3.58
    1 1  6.13  9.82 3.58
    end
    I need to generate a table like this:
    North South
    Control Treatment Control Treatment
    Expats_error mean
    (se)
    Expats_o1_error mean
    (se)
    Expats_o2_error mean
    (se)

    My code so far is:
    Code:
    eststo NorthC : estpost ci expats_error expats_or1_error expats_or2_error if north==1 & treatment==0
                  eststo NorthT : estpost ci expats_error expats_or1_error expats_or2_error if north==1 & treatment==1
                  eststo SouthC : estpost ci expats_error expats_or1_error expats_or2_error if north==0 & treatment==0
                  eststo SouthT : estpost ci expats_error expats_or1_error expats_or2_error if north==0 & treatment==1
     
    esttab NorthC NorthT SouthC SouthT, nostar cells("b(fmt(3))" se(fmt(3) par)) collabels("mean (se)") f noobs
    Question: My problem is labelling the 4 columns as shown above. I need to "group" the first two columns under the label "North" and the second two columns under the label "South".
    I am not sure if this is a question of simply formatting the table differently or if I need to use an entirely different command for this.

    Thank you!

  • #2
    It may be more efficient to use the mean command. If you are outputting to LaTeX, see the -booktabs- option for separating group titles using LaTeX's booktabs package.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(treatment north expats_error expats_or1_error expats_or2_error)
    0 0 20.14  4.82 3.58
    0 0 30.14  2.82 6.58
    1 0  8.14  4.82 2.58
    1 0 23.14  1.82 8.58
    0 1 15.13 29.82 6.58
    0 1  4.13   .82 -.41
    1 1 66.13  1.82 3.58
    1 1  6.13  9.82 3.58
    end
    
    eststo nc: mean expats* if north & !treatment
    eststo nt: mean expats* if north & treatment
    eststo sc: mean expats* if !north &! treatment
    eststo st: mean expats* if !north & treatment
    
    esttab n* s*, mlab(control treatment control treatment, lhs(Variables)) ///
    nonumb mgroups(North South, pattern(1 0 1 0)) se nostar
    Res.:

    Code:
    . esttab n* s*, mlab(control treatment control treatment, lhs(Variables)) ///
    > nonumb mgroups(North South, pattern(1 0 1 0)) se nostar
    
    ----------------------------------------------------------------
                        North                     South             
    Variables         control    treatment      control    treatment
    ----------------------------------------------------------------
    expats_error        9.630        36.13        25.14        15.64
                      (5.500)      (30.00)          (5)      (7.500)
    
    expats_or1~r        15.32        5.820        3.820        3.320
                      (14.50)      (4.000)      (1.000)      (1.500)
    
    expats_or2~r        3.085        3.580        5.080        5.580
                      (3.495)          (.)      (1.500)          (3)
    ----------------------------------------------------------------
    N                       2            2            2            2
    ----------------------------------------------------------------
    Standard errors in parentheses
    Last edited by Andrew Musau; 15 Aug 2024, 08:04.

    Comment


    • #3
      Thank you Andrew, this was helpful. I'll look into LaTeX's booktabs package.

      Comment

      Working...
      X