## Customized tables using option row() of asdoc – Stata

Category:UncategorizedThis is rather a quick example of how to use option row() of asdoc for creating highly customized tables. We are interested in a table that is given bellow.

* Load example datasetsysuse auto,clear* Write the header row of the table with table titleasdoc, row(Dependent variable:domestic or foreign, Domestic mean/frequency, Domestic SD, Foreign mean/frequency, Foreign SD, t-test) title(Summary staticis) save(myfile) replace* Add the second row : \i, adds an empty cellasdoc, row( Model independent variables, \i, \i, \i, \i, \i) append* Use a loop over each variable that include price, mpg, ...foreach var of varlist price mpg rep78 headroom trunk weight length turn{* First summarize each variable for a given sample, that is if foregin is zeroqui sum `var' if foreign==0* Obtain the mean divided by frequencylocal mf=`r(mean)'/`r(N)'* Store the mf and standard deviation variable in accum macroasdoc, accum(`mf', `r(sd)') *now repeat the same for the second sample, ie. when foreing is 1qui sum `var' if foreign==1 local mf=`r(mean)'/`r(N)' asdoc, accum(`mf', `r(sd)')* Conduct a two sample ttest using foregin as a grouping variablettest `var', by(foreign) * Obtain the t-statistics local t : di %9.3f = abs(`r(t)') * Create significance stars if `r(p)'<=0.01 { local star "***" } else if `r(p)'<=0.05{ local star "**" } else if `r(p)'<=0.1{ local star "*" } else { local star " " } local tstar `t'`star' * Add the t-value and stars to the accum macro asdoc, accum(`tstar')* Finally write this complete row where we first write the variable name * and then all accumulated variables that are present in $accum macro.asdoc, row(`var', $accum) }