*! 13may2011 program del version 11.1 mata: DoIt() end version 11.1 mata: void DoIt() { //>>def func<< class dataset scalar meta syntaxl(st_local("0"),(&(vars="[anything]"),&(use="[using]")), (&(add="[a:dd()]"),&(subtract="[s:ubtract()]"),&(perm="[p:ermanent]"),&(formats="[f:ormats]"),&(out="[out()]"))) if (perm) { if (use!="") printf("{txt:Permanent option is not functional with external (ie, {it:using}) files.}\n") else { more= uniqrows(tokens(st_global("_dta[del_more]"))'\tokens(add)') st_global("_dta[del_more]",concat(select(more,!vvmap(more,tokens(subtract)',1))," ")) } } meta.read("labels chars",use) if (!length(meta.vnames)) { printf("{res:No variables in dataset}\n") exit() } if (vars!="") chosen=toindices(listmatch(meta.vnames,vars)) else chosen=1..length(meta.vnames) vnames=meta.vnames[chosen],"_dta" //foreign=missing(meta.bytes) //moredef=empty(tokens(st_global("_dta[del_more]")+" "+add),"scalar") moredef=tokens(st_global("_dta[del_more]")+" "+add) if (length(moredef)) moredef=select(moredef,!listmatch(moredef,subtract)) moredef=moredef,"labels" chars=select(meta.chars,vvmap(meta.chars[,1],vnames,1)) //if (foreign) extypes=select(chars[,3],chars[,2]:=="extype") //if (!length(chars)) chars=J(1,3,"") //so substring works if (length(chars)) { notes=select(chars,substr(chars[,2],1,4):=="note":&substr(chars[,2],5,1):!="0") if (length(notes)) { notes[,3]=substr(notes[,2],5,.):+". ":+notes[,3] notes=dedup(notes,1,3) notes[,2]=J(rows(notes),1,"notes") moredef="notes",moredef } chars=notes\select(chars,vvmap(chars[,2],moredef,1)) } for (v=1;v<=length(chosen);v++) { if (length(onelab=meta.labelsof(chosen[v]))) chars=chars\meta.vnames[chosen[v]],"labels",concat(substr(J(rows(onelab),1," "),1,5:-strlen(onelab[,1])):+concat(onelab," "),"{break}") } r=vvmap(chars[,1],vnames,1) c=vvmap(chars[,2],moredef,1) o=order((r,c),(1,2)) chars=chars[o,];r=r[o];c=c[o] //if (foreign & length(o)) extypes=extypes[o,] lcols=3+(formats/*|foreign*/) body=J(length(chosen),lcols+length(moredef),"") body[,1]=meta.vnames[chosen]' body[,2]=meta.sirtypes[chosen]' body[,3]=strofreal(meta.bytes[chosen]') if (lcols==4) body[,4]=/*foreign?extypes:*/meta.formats[chosen]' body[,cols(body)]=meta.varlabels[chosen]':+" " body=body\("DATASET",J(1,length(moredef)+lcols-2,"-"),meta.dtalabel) linktemplate=sprintf(`"%s00view %sd/del_aux.smcl"##@mark%s@show%s"',char(1),char((96,34,34))+c("sysdir_personal"),char((34,39,2)),char(3)) floc=mksubdirs("del_aux.smcl") unlink(floc) f=fopen(floc,"w") toglobal(&f,"fh") fput(f,"{smcl}") fput(f,meta.path) fput(f,hl="{hline}"+eol(2)) for (i=1;i<=rows(chars);i++) { if (i>1) if(chars[i,1]!=chars[i-1,1]) fwrite(f,hl) fput(f,"{marker "+strofreal(i)+"}{hi:"+chars[i,1]+" "+chars[i,2]+"}"+eol()) fput(f,"{pstd}"+chars[i,3]+eol()) if (chars[i,2]!="labels") body[r[i],lcols+c[i]]=subinstr(subinstr(linktemplate,"@mark",strofreal(i)),"@show",chars[i,2]) else body[r[i],cols(body)]=body[r[i],cols(body)]+ subinstr(subinstr(linktemplate,"@mark",strofreal(i)),"@show",meta.labrefs[chosen[r[i]]]) } fclose(f) body=J(3,cols(body),"")\body\J(2,cols(body),"") body[1,2]=table_styler("integer","res")+"/"+table_styler("real","res")+"/"+table_styler("string","hidata1") body[2,3]="Size (bytes)" body[2,2]=char(1)+"1" body[3,]="Name",J(1,2,char(1)+"1"),J(1,lcols==4,/*foreign?"ExType":*/"Format"),J(1,length(moredef)>1,"Info"),J(1,max((0,length(moredef)-2)),""),"Labels" body[rows(body)-1..rows(body),1..2]="Obs.",strofreal(meta.nobs,"%12.0fc")\"Width",strofreal(sum(meta.bytes),"%12.0fc") t=table_createM(body) asarray(t,"head",3) asarray(t,"spchars",("{c |}","│","↓")) table_code(t,"align","t",.,"<") table_code(t,"class","c",(1,cols(body)),"midstrong") table_code(t,"padL","t",.,0) table_code(t,"padR","t",.,0) table_code(t,"class","cell",pairs(toindices(body[,2]:=="s"),2..lcols),"hidata1") table_code(t,"span","cell",(1,2),length(moredef)+2+(lcols==4)) table_code(t,"span","cell",(2,3),length(moredef)+1+(lcols==4)) table_code(t,"align","cell",(1,2\2,3),"<") table_code(t,"hline","r",rows(body)-3,"clear") table_code(t,"hline","r",rows(body)-2,"thick") table_code(t,"span","cell",pairs(rows(body)-1..rows(body),2),cols(body)-1) table_code(t,"align","cell",pairs(rows(body)-1..rows(body),2),"<") printf("\n") table_present(t,out) } end