How to get value labels as table title using asdoc command in stata?

1.7k Views Asked by At

I have a dataset that has a categorical variable(eg: crops) and continuous variables (e.g: yield, price,input costs). I want to summarize the continuous by each category of crop.

I currently use the below command

label define crops 1"Paddy" 2"Wheat" 3"Vegetables" 4"Trees"
label values crops crops

levelsof crop,local (crop)
foreach i in `crop'{

asdoc sum yield, ///
      stat(N mean median min max iqr p25 p75 ) ///
      label append save(DistributionsMainOutcomes_`today'.doc) ///
      title( Yield: crop`i')
      
asdoc sum price, ///
      stat(N mean median min max iqr p25 p75 ) ///
      label append save(DistributionsMainOutcomes_`today'.doc) ///
      title( Price: crop`i')```

The problem is the tables generated do not have the name of the crops, they just contain the code of the crops from the variable. Any help on how to get value labels on the table title?

1

There are 1 best solutions below

0
Zhiqiang Wang On BEST ANSWER

If understand your question correctly, it is little to do with asdoc. You may just need to pick up value labels. I have tried the following:

clear
sysuse auto,      
seq crop, from(1) to(4)
label define crop 1 "Paddy" 2 "Wheat" 3 "Vegetables" 4 "Trees", modify
label values crop crop
levelsof crop,local (crop)
di `crop'

foreach i in `crop' {
     local title:label crop `i'
     asdoc sum weight, ///
      stat(N mean median min max iqr p25 p75 ) ///
      label append save(try.doc) ///
      title( Yield: `title')

     asdoc sum price, ///
      stat(N mean median min max iqr p25 p75 ) ///
      label append save(DistributionsMainOutcomes_`today'.doc) ///
      title( Price: `title')
}