Announcement

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

  • Interquartile range

    Hello,

    Please can anyone advise how I generate the interquartile range? I have a data example for age here:

    Code:
    . sum age, detail
    
                         Age at recruitment
    -------------------------------------------------------------
          Percentiles      Smallest
     1%           41             40
     5%           44             40
    10%           47             40       Obs                 990
    25%           53             40       Sum of Wgt.         990
    
    50%           60                      Mean            58.5101
                            Largest       Std. Dev.       7.68262
    75%           65             70
    90%           68             70       Variance       59.02265
    95%           69             70       Skewness      -.5442946
    99%           69             70       Kurtosis       2.248327

  • #2
    Joe;
    median (AKA 50% pecentile)=60; IQR: 53;65.
    Code:
    . sum age, detail
    
                         Age at recruitment
    -------------------------------------------------------------
          Percentiles      Smallest
    1%           41             40
    5%           44             40
    10%           47             40       Obs                 990
    25%           53             40       Sum of Wgt.         990
    
    50%           60                      Mean            58.5101
                            Largest       Std. Dev.       7.68262
    75%           65             70
    90%           68             70       Variance       59.02265
    95%           69             70       Skewness      -.5442946
    99%           69             70       Kurtosis       2.248327
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Thanks!

      Comment


      • #4
        Carlo gave the best approach.

        If you wish to automatically calculate the IQR, this code may be helpful as well:

        Code:
        . sysuse auto
        (1978 Automobile Data)
        
        . quietly summarize mpg, detail
        
        . di r(p25)
        18
        
        . di r(p75)
        25
        
        . display "interquartile range = " r(p75) - r(p25)
        interquartile range = 7
        Best regards,

        Marcos

        Comment


        • #5
          Some other things: tabstat, egen, collapse, ...

          Code:
          . sysuse auto, clear
          (1978 Automobile Data)
          
          . tabstat mpg, by(foreign) s(n p25 p75 iqr)
          
          Summary for variables: mpg
               by categories of: foreign (Car type)
          
           foreign |         N       p25       p75       iqr
          ---------+----------------------------------------
          Domestic |        52      16.5        22       5.5
           Foreign |        22        21        28         7
          ---------+----------------------------------------
             Total |        74        18        25         7
          --------------------------------------------------
          
          . egen iqr = iqr(mpg), by(foreign)
          
          . help  collapse

          Comment


          • #6
            note also that there are several commands that directly give the iqr including -table- and -tabstat-

            Comment


            • #7
              Hello,
              I wanted to interpret my result by interquartile range (IQR), e.g., per one IQR. I have continuous predictor variable (x) and create this in stata:
              egen IQR1_x=iqr(x)
              gen IQR2_x=x/IQR1_x

              then, I am going to use "IQR2_x" in my model and interpret as 'the change in the outcome var per one IQR change in the predictor (X). Am I right or, is there a way I can do that?
              I appreciated any support in advance.

              Comment


              • #8
                Well,

                value / IQR (1)

                and

                (value MINUS median) / IQR (1')

                would be analogues of

                value / SD (2)

                and

                (value MINUS mean) / SD (2')

                and the only question is whether they do what you want. For any given variable, (1) and (2) would be perfectly correlated, but there are some other pitfalls, including a possible extreme where the IQR is zero and the result is undefined. As a way to standardize variables (1) and (1') are not guaranteed to resist outliers as they are linear transformations and the IQR could be relatively small in a highly skewed distribution.

                Comment


                • #9
                  Great thanks! Nick Cox, these points are really helpful. Taking your these suggestions into account, I prefer to standardize the value so that decided to use 'value MINUS median) / IQR'.

                  Thanks again for prompt assistance!

                  Comment

                  Working...
                  X