Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Summarizing continuous variables by categories.

    I have datasets which has a categorical variable(e.g : Crops) and few continuous variables (e.g: price, yield, area ). I want to write a loop which will summarize price by each category of crops. I tried using "levelsof" cmd but i get the same result for all the variables. I used the command below. Any advice on this would be helpful.

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

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

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


  • #2
    Without seeing your data, I would think that the issue is that you've defined `i' but haven't used it. I would think you'd want:

    Code:
    levelsof crop,local (crop)
    foreach i in `crop'{
    
    asdoc sum price if crop == "`i'", ///
    stat(N mean median min max iqr p25 p75 ) ///
    label append save(DistributionsMainOutcomes_`today'.doc) ///
    title( Price)
    
    asdoc sum yield if crop == "`i'" , ///
    stat(N mean median min max iqr p25 p75 ) ///
    label append save(DistributionsMainOutcomes_`today'.doc) ///
    title( Yield)
    }

    Comment

    Working...
    X