Hi everyone.
I am using Stata 14.0 on Mac 10.12.
I working with a dataset of around 4000 entries. I want to create a loop which reads through a specific subset of observations and then using expand, produces n-1 amount of lines as the value presented in another variable. To be more precise, I have created a dummy variable called multi-year_duration_dum which assigns 1 to all entries which span more than a year so that they are easily identifiable. I have also created a variable called cal_year_duration which denotes the number of years an entry spans. Now, what I want to do is create as many copies of each multi year project (categorical variable multi_year_duration_dum) as the number of year it spans (cal_year_duration).
Thank you so much in advance, and let me know if I have to provide further information.
I am using Stata 14.0 on Mac 10.12.
I working with a dataset of around 4000 entries. I want to create a loop which reads through a specific subset of observations and then using expand, produces n-1 amount of lines as the value presented in another variable. To be more precise, I have created a dummy variable called multi-year_duration_dum which assigns 1 to all entries which span more than a year so that they are easily identifiable. I have also created a variable called cal_year_duration which denotes the number of years an entry spans. Now, what I want to do is create as many copies of each multi year project (categorical variable multi_year_duration_dum) as the number of year it spans (cal_year_duration).
Thank you so much in advance, and let me know if I have to provide further information.
Code:
* Example generated by -dataex-. clear input float(start_year end_year cal_year_duration same_year_duration_dum multi_year_duration_dum) 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1975 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1976 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1977 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1978 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1979 . . 1 0 1980 . . 1 0 1980 1980 1 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 1980 . . 1 0 end
Comment