You are incorrectly referring to r(N_1)
and r(N_2)
as r(N 1)
and r(N 2)
respectively.
In the toy example provided in your previous post, i have corrected this mistake and i inserted six additional lines in bold, which achieve what you want:
sysuse auto, clear
local i = 0
foreach v of var mpg price weight length displacement {
local ++i
quietly ranksum `v', by(foreign) porder
scalar pval = 2*normprob(-abs(r(z)))
if `i' == 1 {
display %20s "P-Value", %5s "PValue2", %5s "Porder1", %5s "group 1", %5s "group 2"
display ""
}
display "`v'{col 14}" %05.3f pval " " %6.4e pval " " %05.3f r(porder) ///
" " %05.3f r(N_1) " " %05.3f r(N_2)
}
The first display
command acts as a header, but you will have to play with the values to get the desired spacing. The second merely adds a blank line.
The counter macro i
serves to display
the header and blank lines only in the first step of the for
loop instead of them repeating for each variable.
The results are illustrated below:
P-Value PValue2 Porder1 group 1 group 2
mpg 0.002 1.9e-03 0.271 52.000 22.000
price 0.298 3.0e-01 0.423 52.000 22.000
weight 0.000 3.8e-07 0.875 52.000 22.000
length 0.000 9.4e-07 0.862 52.000 22.000
displacement 0.000 1.1e-08 0.921 52.000 22.000
For more information about output formatting using the display
command, type help format
in Stata's command prompt.