Announcement

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

  • Univariate Diff-in-Diff test of medians

    I have a panel data set. The observations are conditionally sorted on two dimensions. I sorted observations into quartiles by variable A, and then conditionally sorted the observations into quartiles by variable B within the variable A quartiles, yielding 16 groups.

    I calculated the mean and median of my Y variable for each group. Then I calculated the difference in means and medians between firms in the highest and lowest variable A quartiles (for each Variable B quartile). Now I want to test whether the differences in means and medians that I just calculated are significantly different in the highest and lowest variable B quartiles.

    So essentially it is a univariate diff-in-diff test. I was able to do this for the means, but I can't figure out how to do it for the medians. Does anyone know?
    Last edited by Niel Smith; 29 Jun 2017, 08:46.

  • #2
    Niel:
    welcome to the list.
    A feasibe option for difference in medians is reported in the following toy-example:
    Code:
    . use "http://www.stata-press.com/data/r14/nlswork.dta", clear
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . ranksum age if idcode<=2, by(idcode)
    
    Two-sample Wilcoxon rank-sum (Mann-Whitney) test
    
          idcode |      obs    rank sum    expected
    -------------+---------------------------------
               1 |       12       142.5         150
               2 |       12       157.5         150
    -------------+---------------------------------
        combined |       24         300         300
    
    unadjusted variance      300.00
    adjustment for ties       -1.43
                         ----------
    adjusted variance        298.57
    
    Ho: age(idcode==1) = age(idcode==2)
                 z =  -0.434
        Prob > |z| =   0.6643
    
    . return list
    
    scalars:
                    r(N_2) =  12
                    r(N_1) =  12
                  r(Var_a) =  298.5652173913043
                      r(z) =  -.434051896082475
                r(sum_exp) =  150
                r(sum_obs) =  142.5
                 r(group1) =  1
    
    . bootstrap r(z), reps(10000):ranksum age if idcode<=2, by(idcode) nodots
    (running ranksum on estimation sample)
    option nodots not allowed
    an error occurred when bootstrap executed ranksum
    r(198);
    
    . bootstrap r(z), reps(10000)nodots:ranksum age if idcode<=2, by(idcode)
    
    Warning:  Because ranksum is not an estimation command or does not set e(sample), bootstrap has no way to
              determine which observations are used in calculating the statistics and so assumes that all
              observations are used.  This means that no observations will be excluded from the resampling because
              of missing values or other reasons.
    
              If the assumption is not true, press Break, save the data, and drop the observations that are to be
              excluded.  Be sure that the dataset in memory contains only the relevant data.
    
    Bootstrap results                               Number of obs     =         24
                                                    Replications      =     10,000
    
          command:  ranksum age, by(idcode)
            _bs_1:  r(z)
    
    ------------------------------------------------------------------------------
                 |   Observed   Bootstrap                         Normal-based
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _bs_1 |  -.4340519   .9981592    -0.43   0.664    -2.390408    1.522304
    ------------------------------------------------------------------------------
    
    . estat bootstrap, all
    
    Bootstrap results                               Number of obs     =         24
                                                    Replications      =      10000
    
          command:  ranksum age, by(idcode)
            _bs_1:  r(z)
    
    ------------------------------------------------------------------------------
                 |    Observed               Bootstrap
                 |       Coef.       Bias    Std. Err.  [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _bs_1 |   -.4340519   .0069415   .99815921   -2.390408   1.522304   (N)
                 |                                      -2.343773    1.55339   (P)
                 |                                      -2.320017   1.582628  (BC)
    ------------------------------------------------------------------------------
    (N)    normal confidence interval
    (P)    percentile confidence interval
    (BC)   bias-corrected confidence interval
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X