Customized tables using option row() of asdoc – Stata

  • 0

Customized tables using option row() of asdoc – Stata

Category:Uncategorized

This 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 dataset
sysuse auto,clear

* Write the header row of the table with table title
asdoc, 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 cell
asdoc, 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   zero
  qui sum `var' if foreign==0

  * Obtain the mean divided by frequency
  local mf=`r(mean)'/`r(N)'

   * Store the mf and standard deviation variable in accum macro
  asdoc, accum(`mf', `r(sd)')

* now repeat the same for the second sample, ie. when foreing is 1
  qui 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 variable
  ttest `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) 
}

Leave a Reply

two × four =