#delim cr version 6.0 /* Examples for the STB bulletin submission for somersd */ /* Open log file */ log using example1.log,replace capture noisily{ /* Beginning of main capture block */ /* Use auto data set and define additional variables */ use auto,clear desc /* Create manuf variable */ gene str18 manuf=ltrim(make) replace manuf=substr(manuf,1,index(manuf," ")-1) replace manuf=make if(index(make," ")<=1) tab manuf,missing /* Create symbol variable for foreign cars */ gene str1 forsym="D" replace forsym="F" if(foreign) /* Demo of Somers' D */ /* Ranksum tests */ ranksum mpg,by(foreign) ranksum weight,by(foreign) /* Somers' D with CIs */ somersd foreign mpg weight lincom -weight-mpg /* Somers' D (z-transformed) with CIs */ somersd foreign mpg weight,tran(z) lincom -weight-mpg /* Somers' D (z-transformed and clustered) with CIs */ somersd foreign mpg weight,tran(z) cluster(manuf) lincom -weight-mpg /* Plot mpg against weight to visualize message of Somers' D */ grap mpg weight,s([forsym]) /* */ xlab(1000,2000,3000,4000,5000) ylab(0,5,10,15,20,25,30,35,40,45) /* */ saving(fig1.gph,replace) /* Create encapsulated PostScript graphics (using gphpen, which I have and most Stata 6.0 users don't) */ gphpen fig1.gph /deps /n /ofig1.eps /* Demo of Kendall's tau-a */ /* Significance tests */ ktau mpg mpg ktau mpg weight ktau mpg displ /* Kendall's tau-a with CIs */ somersd mpg weight displ,taua lincom weight-displ /* Kendall's tau-a (z-transformed) with CIs */ somersd mpg weight displ,taua tr(z) lincom weight-displ /* Kendall's tau-a (z-transformed and clustered) with CIs */ somersd mpg weight displ,taua tr(z) cluster(manuf) lincom weight-displ /* Greiner's rho */ somersd mpg weight displ,taua tr(zrho) /* End of main capture block */ } /* Close log file and exit */ log close exit