1

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?

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
  • `asdoc` is community-contributed. Its author, Attaullah Shah, watches Statalist, but not SO so far as i know. I'd say your chances of a good answer were much greater on Statalist. If you cross-post, please flag that here and also there with a URL of the other post. – Nick Cox Jun 20 '20 at 09:08
  • Nothing here is reproducible without a data example. The local macro `today` is not defined. I have nothing against `levelsof` (I wrote it, originally), but your loop would be simpler as a loop over distinct values 1 to 4 known in advance. None of that is an answer; just commenting. – Nick Cox Jun 20 '20 at 09:12
  • I don't use `asdoc` but don't see how you would get different results each time around the loop, as only your title text changes. – Nick Cox Jun 20 '20 at 09:15
  • But you are asking for the values 1 to 4 to be displayed, and that is what you will get, at most. To look up labels, use the syntax at `help macro`, namely `local show : label (crop) \`i' ` and then pass the local macro `show` to `asdoc`. – Nick Cox Jun 20 '20 at 09:32

1 Answers1

2

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')
}     
Zhiqiang Wang
  • 6,206
  • 2
  • 13
  • 27