Announcement

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

  • For each i, calculate median value of observations in the dataset whose value falls within an interval defined by i's value

    Hello!

    I have 430 observations, each of whom declare a GOAL time (in seconds), and whose FINISH time is observed (in seconds)

    For each individual, I define a set of close times based on their own GOAL time:

    gen goal_minus_80min = GOAL - 4800
    gen goal_minus_10min = GOAL - 600
    gen goal_minus_5min = GOAL - 300
    gen goal_minus_1min = GOAL - 60
    gen goal_plus_1min = GOAL + 60
    gen goal_plus_5min = GOAL + 300
    gen goal_plus_10min = GOAL + 600
    gen goal_plus_64min = GOAL + 3840

    For each observation, I now want to create a set of variables which are the median FINISH time of other people whose FINISH time falls between intervals defined by these close goal times.

    E.G. For person i, what is the median finish time for those who finished between i's goal_minus_80min and goal_minus_10min (call this interval t_1)?

    gen id = _n
    gen t_1 = 0
    forvalues id = 1(1)430 {
    egen t_1_`id' = median FINISH if FINISH >= goal_minus_80min & FINISH <= goal_minus_10min
    replace t_1 = t_third_neg_`id'
    }

    All I get is the t_1 vector of 0s stored from line 2, not replaced by the calculation within the loop.

    I suspect the egen line is just running on i's data, not looking over the whole dataset?

    Any thoughts appreciated!

    Jess

  • #2
    Code:
    rangestat (median) FINISH, interval(FINISH goal_minus_80_min goal_minus_10_min)
    rangestat.ado is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    Comment

    Working...
    X