Announcement

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

  • Summary statistics & conditional logic

    Hi there! I'm having some trouble working with summary statistics and conditional logic. Below is the code I have written so far.

    Code:
    sysuse auto, clear
    foreach var of varlist price mpg rep78 headroom trunk weight length turn displacement gear_ratio {
        tabstat `var', by(`var') statistics(n mean sd q iqr)
        tabulate `var', sort
    }
    What I would like to do is generate a list of variables (not observations) with an interquartile range of less than 2, a mean greater than or equal to 3, and a median greater than or equal to 3. What would be the best way of doing this? Does it involve the egen command?

    Thank you for any/all suggestions!

  • #2
    Code:
    sysuse auto, clear
    local wanted
    
    foreach v of varlist price mpg rep78 headroom trunk weight length turn ///
        displacement gear_ratio {
        summ `v', detail
        if r(mean) >= 3 & `r(p50)' >= 3 & (r(p75)-r(p25)) < 2 {
            local wanted `wanted' `v'
        }
    }
    
    display `"`wanted'"'

    Comment


    • #3
      Thanks so much, Clyde!

      Comment

      Working...
      X