Sunday, January 9, 2022

Generating new variable from calculated dummy variables

I'm very new to Stata (switching from SAS), and am trying to generate the code to solve for what is probably a very simple problem for most experienced Stata users. Here goes:
  • I'm using a data set with approximately 12,950 results.
  • I've already calculated 4 dummy variables, which are: VAR1, VAR2, VAR3, and VAR4
  • I want to generate a new variable, VAR5, which will be the result of five possible outcomes. See the following table as an example:
Possible Dummy Variables Desired
Outcomes VAR1 VAR2 VAR3 VAR4 VAR5
1 96 64 32 12 96
2 . 62 30 13 62
3 . . 24 10 24
4 . . . 11 11
5 . . . . .
  • What I want to have in VAR5 is the result from the earliest VAR, else "."
  • As can be seen in Outcome 1, VAR5 = the result from VAR1 (96), since it is the earliest. Outcome 2 = the VAR2 result (62) since VAR 1 = ".", Outcome 3 = the VAR3 result since VAR1 and VAR2 = ".", Outcome 4 = VAR4 result since VAR1, VAR2 and VAR3 are all ".", and, finally, Outcome 5 would return "." since VAR1, VAR2, VAR3 and VAR4 are all "."
I would appreciate any and all assistance.

Cheers!

No comments:

Post a Comment