#delim ; version 6.0; * Certify somersd using the Auto data *; * Open log file *;log using cert1.log,replace; capture noisily{ * Beginning of main capture block *; * Begin certification script *; cscript "somersd: Somers' D and Kendall's tau-a" adofile somersd; * 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; * Show that replay works as expected *; somersd foreign mpg weight length; somersd; somersd,level(99); esti clear; rcof "noisily somersd"==301; rcof "noisily somersd,level(99)"==301; * Show that Somers' D for binary y-variables is the difference between proportions (with similar variance) *; scal tiny=1e-14;scal small=1e-3; * Create binary variables to compare between domestic and foreign cars *; gene byte dear=price>5006.5; gene byte heavy=weight>3190; gene byte bulky=displ>196; gene byte guzzler=mpg<20; summ dear heavy bulky guzzler; * Create matrices of Somers' D estimates and variances *; somersd foreign dear heavy bulky guzzler; matr beta=e(b);matr vari=vecdiag(e(V)); * Do regressions to find differences between proportions and check that differences are equal to corresponding Somers' D estimates and that their variances are similar to corresponding Somers' D variances *; regr dear foreign,robust; matr breg=e(b);matr vreg=e(V); matr bs=beta[1,"dear"];matr br=breg[1,"foreign"]; assert mreldif(bs,br)