#delim ; * Certify somersd using the auto data. This certification script uses the following STB additions: jknife (from sg34 in STB-24) *; * Begin certification script *; cscript "somersd: Somers' D and Kendall's tau-a" adofile somersd; * Input auto data set into memory and define additional variables. *; clear;set matsize 200; 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); lab var manuf "Manufacturer"; tab manuf,missing; * Create test weight variable *; gene wtest=mod(_n,5); lab var wtest "Test weight variable"; tab wtest,missing; * Define if and in test expressions *; global iftest="if(mod(_n,2))"; global intest="in 33/64"; tab wtest $intest $iftest,missing; * Test set 1. Show that replay works as expected. *; somersd foreign mpg weight length,tr(z); somersd; somersd,level(99); somersd,ci(asci);matr list asci; somersd,level(99) ci(asci);matr list asci; esti clear; rcof "noisily somersd"==301; rcof "noisily somersd,level(99)"==301; rcof "noisily somersd,ci(asci)"==301; rcof "noisily somersd,level(99) ci(asci)"==301; * Test set 2. Show that out-of-range levels fail as expected. *; somersd foreign mpg weight length,tr(z); rcof "noisily somersd,level(100)"==198; rcof "noisily somersd,level(9)"==198; rcof "noisily somersd foreign mpg weight length,tr(z) level(100)"==198; rcof "noisily somersd foreign mpg weight length,tr(z) level(9)"==198; * Test set 3. Show that predict fails as expected. *; somersd foreign mpg weight length,tr(z); rcof "noisily predict"==498; rcof "noisily predict yhat"==498; rcof "noisily predict yhat,xb"==498; * Test set 4. Show response to tiny numbers of observations. *; scal tiny=1e-9; rcof "noisily somersd mpg weight length foreign [fweight=0],taua"==2000; somersd mpg weight length foreign in 1/1,taua; matr b=e(b);matr vce=e(V); matr zb=0*b;matr zvce=0*vce; assert mreldif(b,zb)0); expand wtest; disp "Expanded data, without weights"; somersd foreign mpg weight length, `taua' `cluster' `transf'; matr def b0=e(b);matr def v0=e(V);scal n0=e(N);scal nc0=e(N_clust); restore; disp "Unexpanded data, with fweights"; somersd foreign mpg weight length `if' `in' [fwei=wtest] ,`taua' `cluster' `transf'; matr def b1=e(b);matr def v1=e(V);scal n1=e(N);scal nc1=e(N_clust); assert mreldif(b1,b0)