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
How to plot linearity tests and confidence interval for the thresholds in Threshold of Hansen (1997)?Hello, I am estimating threshold effect of tax revenue on growth for a single country using command…
Keeping duplicate observations with the true value in other variablesHi Stata users, I have a problem looping over string values. I have a data set that contains duplic…
Interaction term insignificance & Marginsplot problemHi all, My initial pooled OLS estimation yields results with statistically significant coefficients…
Duplication of ID variables in panel dataHi All. I have the following duplication of data in id & p_id, which I need to resolve. This da…
how to create this table?Array I succeed to run these 6 regressions. The first 3 regressions are OLS and the last 3 columns…
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