Hi everyone,
After running the following "teffects psmatch" command:
I am developing code to display descriptive statistics for the outcome (bweight) in the exposed and unexposed groups after the matching process. To do this I have used the following Mata code:
This code denotes the post-matching exposed group as "w1" and the post-matching unexposed group as "w0" and extracts the minimum, maximum and mean in both the exposed and unexposed groups from the Mata matrix. I used a manual calculation of ATE [mean(w1)-mean(w0)] to verify my outputs against the automated Stata ATE output.
However I cannot find a way to calculate the median value in the exposed and unexposed groups (I am aware the median is not particularly relevant for birthweights in this example but I am using this stata dataset for this post but the original problem relates to a separate dataset where the median is more appropriate). The only method I can find so far is using the final two Mata commands "w0" and "w1" which list the birthweights in the exposed and unexposed groups after matching as a column vector, allowing me to manually calculate the median from this column. I'm sure there must be an easier way similar to the "min", "max" or "mean" commands within Mata or by exporting the "w0" and "w1"columns to Stata und utilizing "centile" or "summarize, detail" in Stata code but I can't work out how to do it.
If anyone has any suggestions or help it would be appreciated.
Thanks,
Adam
After running the following "teffects psmatch" command:
Code:
use http://www.stata-press.com/data/r13/cattaneo2 teffects psmatch (bweight) (mbsmoke married mage medu fbaby), nneighbour(1) gen(stub)
Code:
gen byte touse = e(sample) mata: i = st_data(.,"stub*","touse") n = cols(i):-rowmissing(i) t = st_data(.,"mbsmoke","touse") w = w1 = w0 = st_data(.,"bweight","touse") for (j=1; j<=rows(i); j++) { if (t[j]) { w0[j] = mean(w[i[|j,1\j,n[j]|]]) } else { w1[j] = mean(w[i[|j,1\j,n[j]|]]) } } mean(w1)-mean(w0) mean(w0) min(w0) max(w0) mean(w1) min(w1) max(w1) w0 w1 end
This code denotes the post-matching exposed group as "w1" and the post-matching unexposed group as "w0" and extracts the minimum, maximum and mean in both the exposed and unexposed groups from the Mata matrix. I used a manual calculation of ATE [mean(w1)-mean(w0)] to verify my outputs against the automated Stata ATE output.
However I cannot find a way to calculate the median value in the exposed and unexposed groups (I am aware the median is not particularly relevant for birthweights in this example but I am using this stata dataset for this post but the original problem relates to a separate dataset where the median is more appropriate). The only method I can find so far is using the final two Mata commands "w0" and "w1" which list the birthweights in the exposed and unexposed groups after matching as a column vector, allowing me to manually calculate the median from this column. I'm sure there must be an easier way similar to the "min", "max" or "mean" commands within Mata or by exporting the "w0" and "w1"columns to Stata und utilizing "centile" or "summarize, detail" in Stata code but I can't work out how to do it.
If anyone has any suggestions or help it would be appreciated.
Thanks,
Adam
Comment