Hello all,
I was writing a wrapper to call medians, ranges and Mann-Whitney p-values but the wrapper is failing to call the second factor variable data in the loop. I am guessing there is something wrong in my loop specification. Showing the auto data set with my code below for reproducibility. You will see that it gives me data for all p-values correctly, but fails to generate anything for the second variable foreign. I switched the order and then I get data for medians etc for foreign 0 and foreign 1 from that matrix.
I was writing a wrapper to call medians, ranges and Mann-Whitney p-values but the wrapper is failing to call the second factor variable data in the loop. I am guessing there is something wrong in my loop specification. Showing the auto data set with my code below for reproducibility. You will see that it gives me data for all p-values correctly, but fails to generate anything for the second variable foreign. I switched the order and then I get data for medians etc for foreign 0 and foreign 1 from that matrix.
Code:
sysuse auto, clear gen byte w2 = cond(weight>3000, 1, 0) local x gear_ratio local f w2 foreign // Convert p-values to appropriate formatting needed *--------------------------------------------------- foreach v of local f { ranksum `x', by(`v') local p = `r(p)' if `p'>=0.056 { local p`v' = "= " + string(`p', "%3.2f") } if `p'>=0.044 & `p'<0.056 { local p`v' = "= " + string(`p', "%5.4f") } if `p' <0.044 { local p`v' = "= " + string(`p', "%4.3f") } if `p' <0.001 { local p`v' "< .001" } if `p' <0.0001 { local p`v' "< .0001" } } // Collect all stats below for all variables around round to one decimal *----------------------------------------------------------------------- foreach v of local f{ levelsof `v', local(mylev) tabstat `x', by(`v') statistic(p25 p50 p75 min max) save return list } local col 0 foreach v of local f{ local ++col foreach lev of local mylev{ local j= `lev'+1 mat list r(Stat`j') matmap r(Stat`j') B`j', map(round(@, 0.1)) mat list B`j' local `v'lqr`lev' `=round(B`j'[1,`col'], 0.01)' local `v'med`lev' `=round(B`j'[2,`col'], 0.01)' local `v'uqr`lev' `=round(B`j'[3,`col'], 0.01)' local `v'min`lev' `=round(B`j'[4,`col'], 0.01)' local `v'max`lev' `=round(B`j'[5,`col'], 0.01)' } } di `foreignmax0' di `w2min1'
Comment