*! 8oct2010 program dd, rclass version 11.1 return clear mata: DoIt() return local varlist `varsback' end version 11.1 mata: void DoIt() { //>>def func<< class dataset scalar meta syntaxl(st_local("0"),(&(vars="[anything]"),&(use="[using]")), (&(hilight="[hi:light()]"),&(plain="[p:lain]"),&(alpha="[a:lpha]"),&(out="[out()]"))) if (strlen(hilight) & plain) errel("Only one of -hilight- and -plain- can be specified.") meta.read("labels",use) vars=meta.varlist(vars) if (alpha) vars=vars[order(meta.vnames[vars]',1)'] st_local("varsback",concat(meta.vnames[vars]," ")) if (!length(vars)) { printf("{res:No variables}") exit() } cats=his=J(1,length(vars),0) if (!plain) { if (strlen(hilight)) his=vvmap(vars,meta.varlist(hilight),1):>0 else { cats=meta.iscat(vars) his=meta.sirtypes[vars]:=="s" } } psize=c("pagesize")-3 pvars=colshape((meta.vnames[vars],J(1,psize-mod(length(vars),psize),"")),psize)' sizes=colmax(strlen(pvars):+1) pages=(1,1) while ((c=pages[rows(pages),2]+1)<=cols(pvars)) { if (sum(sizes[pages[rows(pages),1]..c])1?J(2*rp,1,NULL):J(rp,1,NULL) if (rp>1) div=(char(1)+"1")*sizes[pages[1,1]]+(char(1)+"2")*(sum(sizes[pages[1,1]+1..pages[1,2]-1])-1) t=0 for (p=1;p<=rp;p++) { tables[++t]=&table_createM(pvars[,pages[p,1]..pages[p,2]]) table_code(*tables[t],"padL","t",.,0) table_code(*tables[t],"padR","t",.,0) table_code(*tables[t],"class","t",.,"midstrong") pspan=(pages[p,1]-1)*psize+1..min((length(vars),pages[p,2]*psize)) table_code(*tables[t],"class","cell",pcells(pspan,cats,psize),"weaker") table_code(*tables[t],"class","cell",pcells(pspan,his,psize),"stronger") if (rp>1) { tables[++t]=&table_createM(div) //table rendering is destructive(!) necessitating multiple identical tables table_code(*tables[t],"class","t",.,"midstrong") asarray(*tables[t],"spchars",(" "," "," "\"{c -}","─","─")) } } if (!plain&hilight=="") { //what should hilight criteria be? tables=&table_createM(table_styler("Key: numeric","midstrong")+table_styler(" num/labeled","weaker")*!missing(meta.bytes)+table_styler(" string","stronger"))\tables table_code(*tables[1],"hline","t",.,"alt") } printf("\n") tables_present(tables,out) } real matrix pcells(real vector span, real vector selector, real scalar rows) { pvect=toindices(selector[span])' if (length(pvect)) return((mod1(pvect,rows),trunc((pvect:-1)/rows):+1)) else return(J(0,2,.)) } end