I have a dataset that looks as follows. For each state, I know which individuals are accepted (acc = 1) or rejected (acc = 0) on the basis of two scores x and y. A want to say that a rejection is bad if there is an individual in that state that is accepted and that has worse scores on both x and y. I can compute this looping through states, accepted, and rejected candidates, see below. However, I was looking for suggestions on how to make the program more efficient.
gen obs = _n
gen bad = 0 if acc = 0
gen obs = _n
glevelsof state if acc == 1
local stloop "`r(levels)'"
foreach s in `stloop' {
glevels of obs if state == `s' & acc == 1
local accit "`r(levels)'"
glevelsof obs if fstate == `s' if acc == 0
local nsuit "`r(levels)'"
foreach i in `nsuit' {
foreach ac in `accit' {
if x[`i'] > x[`ac'] & y[`i'] > y[`ac'] {
replace bad = 1 if obs == `i'
continue ,break
}
}
}
}
Related Posts with Finding observations that are strictly dominated: how do I eliminate multiple loops
Add common term to a list of different variable labelsHi All, I'm trying to add a common term to the existing variable labels of a dataset, "LPI: ", so t…
how to check whether a variable varies over time for each individual in a panel dataDear Statalist, I have a balanced panel data with life satisfaction for each individual over three …
DiD with kernel PSMDear Statalist users, I am trying to combine a difference-in-difference design with kernel propens…
ranksum test porder optionHi all, Good morning! I have done wilcoxin ranksum test with porder in STATA the variable we are te…
year and month formatHello, I created the month variable into Stata format from 201509 to 2015m9 using the command: Co…
Subscribe to:
Post Comments (Atom)
0 Response to Finding observations that are strictly dominated: how do I eliminate multiple loops
Post a Comment