Announcement

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

  • Create variable defining difference in mean

    Hi all,
    I am trying to do an analysis indicating the difference between difference in mean scores (difference in difference analysis).
    STATA has a option, though i find this difficult.

    At this point I want to create a variable indicating the difference in mean score in my unpaired t-test.

    I hope you can help me out

    Sincerely,
    Anders

  • #2
    Anders:
    welcome to this forum.
    Do you mean something along the following lines?
    Code:
    . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    (1978 automobile data)
    
    . ttest price, unequal by(foreign)
    
    Two-sample t test with unequal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
    ---------+--------------------------------------------------------------------
    Domestic |      52    6072.423    429.4911    3097.104    5210.184    6934.662
     Foreign |      22    6384.682    558.9942    2621.915     5222.19    7547.174
    ---------+--------------------------------------------------------------------
    Combined |      74    6165.257    342.8719    2949.496    5481.914      6848.6
    ---------+--------------------------------------------------------------------
        diff |           -312.2587    704.9376               -1730.856    1106.339
    ------------------------------------------------------------------------------
        diff = mean(Domestic) - mean(Foreign)                         t =  -0.4430
    H0: diff = 0                     Satterthwaite's degrees of freedom =  46.4471
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.3299         Pr(|T| > |t|) = 0.6599          Pr(T > t) = 0.6701
    
    . return list
    
    scalars:
                  r(level) =  95
                     r(sd) =  2949.495884768919
                   r(sd_2) =  2621.915083190759
                   r(sd_1) =  3097.104279086425
                     r(se) =  704.937643377471
                    r(p_u) =  .6700743053648903
                    r(p_l) =  .3299256946351096
                      r(p) =  .6598513892702191
                      r(t) =  -.4429593797298984
                   r(df_t) =  46.44711321147706
                   r(mu_2) =  6384.681818181818
                    r(N_2) =  22
                   r(mu_1) =  6072.423076923077
                    r(N_1) =  52
    
    . g wanted=r(mu_1)-r(mu_2)
    
    . list wanted in 1
    
         +-----------+
         |    wanted |
         |-----------|
      1. | -312.2587 |
         +-----------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X