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
Related Posts with For each i, calculate median value of observations in the dataset whose value falls within an interval defined by i's value
Margins from a mixed model with a log-transformed outcomeI run a mixed model of a log-transformed outcome using ‘mixed’ (and the dfmethod(kroger) option with…
Panel data modelHi, I have a panel dataset whereT=10 and N=77 and found the problem of heteroscedasticity, autocorre…
Changing datesHow can I change a date format in Stata for from this format 06/12/2021 to this format 06-12-2021 …
optimizeHi All, I have a big dataset (2432rows with 6 variables) looks like below. I would like to minimize …
Nested logit with invariant regressorI am trying to use nested logit specification for estimating school choice of households. The first …
Subscribe to:
Post Comments (Atom)
0 Response to For each i, calculate median value of observations in the dataset whose value falls within an interval defined by i's value
Post a Comment