Ciao,
Here is a question about using forval. Say I administer a test that has 10 different version (1 through 10). Then, say I have a variable for which test is administered that is called test_num and goes from 1 to 10. Say I want to create a dummy variable called test_1 if the test_num ==1 and that I want to do this for all values of test_num. So basically I want to create an indicator variable (1, 0) for each test version. How can I do this using forval? Below is what I tried but it just generated one variable called test_num equal to 1. Thanks so much.
Here is a question about using forval. Say I administer a test that has 10 different version (1 through 10). Then, say I have a variable for which test is administered that is called test_num and goes from 1 to 10. Say I want to create a dummy variable called test_1 if the test_num ==1 and that I want to do this for all values of test_num. So basically I want to create an indicator variable (1, 0) for each test version. How can I do this using forval? Below is what I tried but it just generated one variable called test_num equal to 1. Thanks so much.
Code:
forval test_num=1/10 { gen test_`test_num' = 1 if `test_num' = `test_num' replace test_`test_num' = 0 if `test_num' != `test_num' }
Comment