I am having a challenge of creating a new variable that reflects the cases and controls for a particular case(spin).
The variable "spin" reflects the record with the case as "Yes".
The variable "ntdccset" shows groupings of records.
I now want to create a new variable that reflects 1-Case and 2-Control if the variable "spin" is yes
Something similar to this:
ntdccset | spin | newspin |
7 | Yes | 1 |
7 | No | 2 |
7 | No | 2 |
7 | No | 2 |
13 | No | . |
13 | No | . |
13 | No | . |
13 | No | . |
15 | Yes | 1 |
15 | No | 2 |
15 | No | 2 |
15 | No | 2 |
16 | No | . |
16 | No | . |
16 | No | . |
16 | No | . |
17 | No | 2 |
17 | Yes | 1 |
17 | No | 2 |
17 | No | 2 |
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int ntdccset float spin 7 1 7 0 7 0 7 0 13 0 13 0 13 0 13 0 15 1 15 0 15 0 15 0 16 0 16 0 16 0 16 0 17 0 17 1 17 0 17 0 end label values spin yes_no label def yes_no 0 "No", modify label def yes_no 1 "Yes", modify
Thanks
Robert
0 Response to Using foreach syntax to create new variable
Post a Comment