Hi,
I have the following categorical variable which has 3 categories denoting the kind of treatment a patient receives. As this is a longitudinal dataset, the treatment type may change over time.
There is significant amount of missing data which can be replaced with already available data under certain conditions. There is where I need some help in tweaking my Stata syntax.
Example of the categorical treatment variable, where 'n' indicates measurement occasion:
I have two scenarios to deal with:
1. ID 1 & ID 2: only have one treatment category assigned to them. I can safely assume that the missing treatment data can be filled-in with already existing information:
2. ID 4 changes from injections to diet, but the missing data for injection can be filled-in for occasion 2:
I'm trying to further develop the code below to address the above issues but with not much success. My code replaces all or most missing data for available individuals. How do I make it specific for each scenario above?
Thanks for any help in advance!
Regards
/Amal
I have the following categorical variable which has 3 categories denoting the kind of treatment a patient receives. As this is a longitudinal dataset, the treatment type may change over time.
There is significant amount of missing data which can be replaced with already available data under certain conditions. There is where I need some help in tweaking my Stata syntax.
Example of the categorical treatment variable, where 'n' indicates measurement occasion:
Code:
ID treat n 1 injec 1 1 . 2 1 injec 3 1 . 4 1 injec 5 2 diet 1 2 . 2 2 diet 3 3 . 1 3 . 2 4 injec 1 4 . 2 4 injec 3 4 diet 4 4 diet 5
1. ID 1 & ID 2: only have one treatment category assigned to them. I can safely assume that the missing treatment data can be filled-in with already existing information:
Code:
ID treat n 1 injec 1 1 injec 2 1 injec 3 1 injec 4 1 injec 5 2 diet 1 2 diet 2 2 diet 3
Code:
4 injec 1 4 injec 2 4 injec 3 4 diet 4 4 diet 5
Code:
by id (n), sort: replace treat=treat[_n-1] if treat==.
Regards
/Amal
Comment