Dear Statalisters,
My goal is to convert that subject-triannual data set to one with subject-month observations, and specify the month at which one string variable (named "strvar" below) should change value, according to the var called "exact_time".
I have a data set with four records per subject (subject-year observations, aka multiple-record-per-subject data set), information was recorded every three years for each subject as follows:
"strvar" changes its value every three years. The variable "exact_time" records the exact (month.day.year) moment at which each the variable "strvar" changes its value. Once "strvar" varies, it keeps the same value for the following months, until the moment indicated by the next value of "exact_time"
I want Stata to change the value of "strvar" according to the variable "exact_time". For instance, subject 1 changed value of "strvar" in April 1, 1992, hence, I want Stata to assign the new value of "strvar" in April 1992. The value of "strvar" for subject 1 should remain the same until "exact_time" changes value (November.30.1995), hence, starting in November 1995, subject one should adopt the new value of "strvar". In 1998, "strvar" of subject one changed value once again, this time at the beginning of next year (January.1.1999), hence, "strvar" will adopt a new value starting in January.1999, until subject one's last observation (December 2002). As follows:
I believe this can be achieved in in two steps, the second of which I need your support with:
1. Expand each tri-annual observation 36 times, so as to have monthly-subject observations, i.e., generate var "new_time". I guess this can be achieved through:
2. Instruct Stata to change the value "strvar" according to the date specified by "exact_time", which I have no idea how to do, and for which I would appreciate your support.
Thank you in advance!
My goal is to convert that subject-triannual data set to one with subject-month observations, and specify the month at which one string variable (named "strvar" below) should change value, according to the var called "exact_time".
I have a data set with four records per subject (subject-year observations, aka multiple-record-per-subject data set), information was recorded every three years for each subject as follows:
Subject | time | strvar | exact_time |
1 | 1992 | str_z | April.1.1992 |
1 | 1995 | str_u | November.30.1995 |
1 | 1998 | str_a | January.1.1999 |
2 | 1989 | str_b | January.15.1989 |
2 | 1992 | str_z | June.15.1992 |
2 | 1995 | str_c | August.30.1995 |
I want Stata to change the value of "strvar" according to the variable "exact_time". For instance, subject 1 changed value of "strvar" in April 1, 1992, hence, I want Stata to assign the new value of "strvar" in April 1992. The value of "strvar" for subject 1 should remain the same until "exact_time" changes value (November.30.1995), hence, starting in November 1995, subject one should adopt the new value of "strvar". In 1998, "strvar" of subject one changed value once again, this time at the beginning of next year (January.1.1999), hence, "strvar" will adopt a new value starting in January.1999, until subject one's last observation (December 2002). As follows:
Subject | new_time | strvar |
1 | January.1992 | str_x |
1 | February.1992 | str_x |
1 | March.1992 | str_x |
1 | April.1992 | str_z |
1 | May.1992 | str_z |
1 | June.1992 | str_z |
1 | ... | str_z |
1 | ... | str_z |
1 | October.1995 | str_z |
1 | November.1995 | str_u |
1 | December.1995 | str_u |
1 | . | str_u |
1 | . | str_u |
1 | November.1998 | str_u |
1 | December.1998 | str_u |
1 | January.1999 | str_a |
1 | February.1999 | str_a |
1 | ... | str_a |
1 | ... | str_a |
1 | December 2002 | str_a |
2 | January.1989 | str_z |
2 | February.1989 | str_b |
2 | March.1989 | str_b |
2 | ... | str_b |
2 | December.2002 | str_c |
1. Expand each tri-annual observation 36 times, so as to have monthly-subject observations, i.e., generate var "new_time". I guess this can be achieved through:
Code:
expandcl 36, generate(new_time) cluster(subject)
Thank you in advance!
Comment