I have the dataset below. How can i replace the S3_Q10K with value in S1C_Q0_*? For example if in S3_Q10K is = 1 then i want to replace it with value in S1C_Q0_1, if in S3_Q10K is = 2 then i want to replace it with value in S1C_Q0_2, if in S3_Q10K is = 4 then i want to replace it with value in S1C_Q0_4 and so on.
i used
Code:
replace S3_Q1K = S1C_Q0_1 if S3_Q1K ==1
which worked but i am always told to use short codes thus i didnt want to use the above code 19 times and i was not sure how to use loop code
Thank you so much for your help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(S3_Q10K S3_Q3P S1C_Q0_1 S1C_Q0_2 S1C_Q0_3 S1C_Q0_4 S1C_Q0_5 S1C_Q0_6) 1 . 1 0 . . . . 77 . 1 0 1 . . . 1 . 1 0 . . . . 1 . 1 0 1 1 0 . 2 1 1 1 1 1 0 0 1 1 1 0 1 0 1 0 7 88 1 1 1 0 1 0 3 1 1 0 1 . . . 5 88 1 0 1 0 1 0 6 88 1 0 0 0 1 1 1 1 0 1 1 0 0 . 2 . 1 0 1 1 1 1 2 . 1 0 . . . . 3 1 1 0 1 0 . . 3 1 1 0 1 0 0 1 1 . 1 0 0 0 1 . 1 . 1 0 . . . . 9 . 0 0 0 1 0 1 1 . 1 1 0 1 0 0 5 . 1 0 1 0 1 0 1 1 1 0 1 0 1 1 3 . 1 0 0 1 1 1 2 88 1 0 1 1 . . 2 . 0 1 0 0 0 . 6 88 1 0 0 0 0 1 2 2 1 0 0 1 . . 1 . 1 0 1 1 1 0 6 1 0 1 1 1 1 0 3 . 1 0 1 0 0 1 1 . 1 0 0 0 1 1 44 88 1 0 . . . . 1 . 1 0 1 . . . 6 88 1 0 0 1 1 1 1 . 1 0 0 0 1 . 1 . 1 0 1 0 0 . 2 . 1 0 . . . . 3 . 0 0 1 . . . 3 . 0 1 1 1 1 0 1 . 1 0 0 1 . . 6 6 1 0 0 0 1 1 1 . 1 0 0 0 1 . 1 . 1 0 . . . . 2 . 0 0 1 0 1 . 1 . 0 1 1 1 0 0 1 . 1 0 0 1 1 . . 3 1 1 1 0 0 1 2 1 0 1 0 . . . 1 . 1 0 0 1 . . 7 1 1 0 1 0 1 0 1 . 1 0 1 . . . 2 . 0 0 1 1 0 . 88 . 1 0 . . . . 2 2 0 0 1 1 0 . 4 1 1 0 0 1 . . 2 . 1 0 1 . . . 2 . 1 0 . . . . 1 . 1 0 0 1 1 . 1 . 1 0 1 0 1 0 1 . 0 0 0 1 1 . 2 1 1 0 . . . . 2 . 1 0 0 . . . 3 3 1 0 0 1 0 0 3 . 1 0 1 1 0 0 2 . 1 0 . . . . 1 . 1 0 1 0 1 1 2 . 1 0 0 1 0 0 4 4 1 0 0 1 . . 1 . 1 0 1 0 0 0 5 . 1 0 0 0 1 1 2 88 1 0 1 1 1 0 1 . 1 0 1 0 1 . 3 . 1 0 1 1 1 . 1 . 1 0 . . . . 88 . 1 1 0 0 1 . 1 . 1 0 . . . . 1 1 1 0 0 1 . . 1 . 1 0 1 1 0 0 2 . 1 0 . . . . 11 . 1 0 1 0 1 0 3 2 0 1 1 1 0 0 3 . 1 0 1 0 . . 2 . 1 0 . . . . 1 . 1 0 1 0 . . 3 . 1 0 1 . . . 3 . 1 1 1 1 0 0 4 . 1 0 1 0 . . 3 . 1 0 1 . . . 1 . 1 0 1 1 . . 1 . 1 0 1 1 . . 88 88 1 0 0 1 1 . 88 1 1 0 1 1 1 . 88 . 0 1 1 0 0 . 88 . 1 0 1 . . . 2 . 1 0 1 1 0 . 88 . 1 0 1 . . . 88 . 1 0 1 0 . . 88 . 1 0 1 1 0 0 88 . 0 1 0 1 . . 77 . 1 0 . . . . 88 . 1 0 1 0 . . end
0 Response to Help with replace and egen
Post a Comment