Announcement

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

  • Randomization test and descriptive statistics

    Hi everyone!

    I am trying to replicate a balance test and descriptive statistics similar to the photo attached (but with three treatment groups in my case). I have been googling some command for this but I haven't found any, so I was wondering if any of you have a tip for that. I have Stata16 and I need to convert the table into latex code.

    Thanks a lot!

    Click image for larger version

Name:	1.PNG
Views:	3
Size:	40.7 KB
ID:	1549757

    2.PNG
    Attached Files

  • #2
    What I do is generate an empty matrix with number of rows = number of variables ( you could go plus 1 for totals at the bottom) and number of columns say 3 (depending on what you want to report) means of treated, means of controls and normalized differences. Below I am assuming your indicator variable treated is coded 1 for treated and 2 for controls if not, you can easily recode it or modify the loop accordingly.
    Then I populate the matrix with a loop over the variables and another loop over treated/controls.
    Code:
    local vars x1 x2 x3
    local rows: word count `vars'
    matrix out = J(`rows',3,.)
    forv r = 1/`rows' {
    local v: word `r' of `vars'
    forv c = 1/2 {
    sum `v' if treated == `c', meanonly
    matrix out[`r',`c'] = r(mean)
    }
    }
    In column 3 I report normalized differences (Imbens and Rubin, 2015). For that it may be useful immediately after the summarize command to save the means, st deviations and number of observations in separate macros to use later. For example, after sum for the controls, you would go:
    Code:
    local mean_c = r(mean)
    local sd_c = r(sd)
    local obs_c = r(N)
    Having saved these for both treated and controls, you would calculate the normalized differences and their t-stats as:
    Code:
    local diff = abs(`mean_t'-`mean_c')/sqrt((`sd_t'^2 + `sd_c'^2)/2)
    local t_stat = abs(`mean_t'-`mean_c')/sqrt(`sd_t'^2/`obs_t' + `sd_c'^2/`obs_c')
    Then I use frmttable (net install sg97_5.pkg) to output the matrix nicely formatted. See frmttable's documentation for examples and syntax for latex.
    Last edited by Maria Boutchkova; 28 Apr 2020, 10:29.

    Comment

    Working...
    X