-
Notifications
You must be signed in to change notification settings - Fork 1
/
ccodebook.ado
93 lines (82 loc) · 3.66 KB
/
ccodebook.ado
1
* ccodebook.adocapture program drop ccodebookprogram lcodebook syntax varlist(min=1 max=1) using [if] [in] ,[ caption(string) label(string)] marksample touse, novarlist display _newline as text "Running " as result "\$Id: ccodebook.ado 658 2009-08-18 15:41:09Z mesa $" #delimit ; capture file close myfile; file open myfile `using', write replace; /* this defines the header of the table */ // file write myfile "\begin{longtable}{" _n; file write myfile "\begin{table}[htdp]" _n; file write myfile "\caption{`caption'} \label{`label'} \\" _n; file write myfile "\begin{center}" _n; file write myfile "\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}} l r}" _n; file write myfile ">{\hsize=.50\hsize}X" _n; file write myfile "|>{\hsize=.1\hsize}X" _n; file write myfile ">{\hsize=.15\hsize}X" _n; file write myfile ">{\hsize=.25\hsize}X" _n; file write myfile ">{\hsize=.15\hsize}X" _n; file write myfile ">{\hsize=.15\hsize}X" _n; file write myfile ">{\hsize=.15\hsize}X" _n; file write myfile "|>{\hsize=.65\hsize}X" _n; file write myfile"}" _n; file write myfile "\caption{`caption'} \label{`label'} \\" _n; file write myfile "\hline Variable & Obs & Unique & Missing & Mean & Min & Max & Label \\ \hline " _n; file write myfile "\endfirsthead" _n; file write myfile "\multicolumn{8}{c}%" _n; file write myfile "{{\bfseries \tablename\ \thetable{}: `caption' -- continued}} \\" _n; file write myfile "\hline Variable & Obs & Unique & Missing & mean & Min & Max & Label \\ \hline" _n; file write myfile "\endhead" _n; file write myfile "\hline \multicolumn{8}{r}{{{\small(continued on next page)}}} \\ \hline" _n; file write myfile "\endfoot" _n; file write myfile "\hline" _n; file write myfile "\endlastfoot" _n; /* loop over all variables. Calculates several entries of the codebook table, saves them in a macro and writes the .tex-file line by line .... .*/ quietly describe,simple; /* Hier statt * eine Variablenliste? */ foreach y of var `varlist' { ; /* take care of LaTeX special in Variablenames */ local x = subinstr("`y'","_","\_",.); /* calculate entries of table */ count if `touse'; local observ = r(N); unique `y' if `touse'; /* local observ = r(N); */ local unique = r(sum); quietly tabmiss `y' if `touse'; local missings = r(sum); local missingsperc = r(mean)*100; /* local missingsperc = round(r(missingsperc),0.1); */ local missingsperc = string(`missingsperc',"%9.0f"); quietly sum `y' if `touse'; local mean= round(r(mean),0.1); local mean = string(`mean',"%9.1f"); local min = r(min); local min = string(`min',"%9.1f"); local max = round(r(max),0.1); local max = string(`max',"%9.1f"); local labelofvariable: variable label `y'; /* My addition -- take care of LaTeX special characters in the Variable Labels. */ local labelofvariable = subinstr("`labelofvariable'","_","\_",.); local labelofvariable = subinstr("`labelofvariable'","#","\#",.); local labelofvariable = subinstr("`labelofvariable'","$","\$",.); local labelofvariable = subinstr("`labelofvariable'","%","\%",.); local labelofvariable = subinstr("`labelofvariable'","&","\&",.); local labelofvariable = subinstr("`labelofvariable'","^","\^",.); local labelofvariable = subinstr("`labelofvariable'","{","\{",.); local labelofvariable = subinstr("`labelofvariable'","}","\}",.); file write myfile " \texttt{`x'} & `observ' & `unique' & `missings' (`missingsperc' \%) &`mean' & `min' & `max' & `labelofvariable' \medskip \\ " _n; } ; /* ende der tex-tabelle schreiben */ file write myfile "\hline" _n; file write myfile "\end{longtable}" _n; file close myfile; #delimit crend