Hi! I'm testing that the distribution of two variables is the same across groups using - ksmirnov -. Since I have many groups, I set up a local that counts how many comparisons give a positive outcome (equal distributions). Here is an example of what I do:
where count is the number of pairwise comparisons performed, and pos_count is the number of positive outcomes (equal distribution).
I also have different specifications I want to test (e.g. besides mpg, I want to perform the same test on price) and I would like to report the results in a table (that I want to later export to latex) that has the variables mpg and price on the rows, and the macros pos_count and count on the columns (columns repeated for each year).
Any help on how to do it would be appreciated.
Thanks!
Code:
sysuse auto2.dta, clear * Duplicate obs to create a panel gen dup=2 expand dup gen time=1 bysort make: replace time=time+1 if _n==2 * Create comparison groups tab rep78, nolabel gen rep78_1=(rep78==1) if rep78==1 | rep78==2 // Compare group1 with group2 gen rep78_2=(rep78==1) if rep78==1 | rep78==3 // Compare group1 with group3 gen rep78_3=(rep78==1) if rep78==1 | rep78==4 // and so on. gen rep78_4=(rep78==1) if rep78==1 | rep78==5 gen rep78_5=(rep78==2) if rep78==2 | rep78==3 gen rep78_6=(rep78==2) if rep78==2 | rep78==4 gen rep78_7=(rep78==2) if rep78==2 | rep78==5 gen rep78_8=(rep78==3) if rep78==3 | rep78==4 gen rep78_9=(rep78==3) if rep78==3 | rep78==5 gen rep78_10=(rep78==4) if rep78==4 | rep78==5 * Perform pairwise comparisons of distribution of mpg, for each time period forvalues t=1/2 { local count=0 local pos_count=0 foreach i of numlist 1/10 { ksmirnov mpg if time==`t', by(rep78_`i') local count=`count'+1 if `r(p)'>0.05 { local pos_count=`pos_count'+1 } } dis `count' dis `pos_count' }
I also have different specifications I want to test (e.g. besides mpg, I want to perform the same test on price) and I would like to report the results in a table (that I want to later export to latex) that has the variables mpg and price on the rows, and the macros pos_count and count on the columns (columns repeated for each year).
Any help on how to do it would be appreciated.
Thanks!
Comment