I want to create a new variable based on information in other observations. My data looks like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year str11 player int pts byte(pts_rank proj_rank)
2019 "Tom Brady" . . 10
2018 "Andy Dalton" 275 10 .
2018 "Drew Brees" 300 11 .
2018 "Tom Brady" 283 8 .
end
I want to generate a new variable called "proj_pts", which equals the points "pts" of the player whose pts_rank last year matches the first player's proj_rank this year. I realize this is very confusing, so here is an example. In 2019, Tom Brady is projected to be the 10th best quarterback (proj_rank = 10). I want to project how many points he will get (proj_pts) based on how well the 10th ranked player last year (Andy Dalton) did. Thus, proj_pts should equal 275 for Tom Brady, since that's how many points Andy Dalton scored in 2018. That is, I want my final data to look like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year str11 player int pts byte(pts_rank proj_rank) int proj_pts
2019 "Tom Brady" . . 10 275
2018 "Andy Dalton" 275 10 . .
2018 "Drew Brees" 300 11 . .
2018 "Tom Brady" 283 8 . .
end
How would I do this?
0 Response to Creating a new variable based on information in another observation
Post a Comment