Dear all,
I have a dataset which contains data about women using medication during pregnancy. For every drug I have the total duration of use and the exact start and stop dates of the drug (there can be 1, 2 or 3 episodes in time for the same drug as the drugs can be stopped and restarted). These dates often include periods of time before and after the pregnancy. Now I want to make a variable that describes the duration of the use ONLY during pregnancy; and I started writing a syntax as below but this doesn't always give me the right result when I check the total number of days manually.
I have the start date of the pregnancy (start_preg) and the date of birth (partus) as variables.
azt is the name of the drug, so azt_start1 is the date on which the drug was started first, an azt_stop1 is the date on which it was stopped for the first time. Then azt_stop3 for example is the 3rd time the drug was started (if this was the case). These different episodes are represented by a, b and c.
Furthermore, option 1 is the option that the drug was started before the pregnancy and it was stopped during pregnancy.
Option 2 is the option that the drug was started in pregnancy (so before the partus) and stopped after pregnancy.
Option 3 is the option that the drug was started in pregnancy and was also stopped in pregnancy.
I was wondering if you see a mistake here or if you have ideas about other ways to create a variable that gives me the total duration of drug use only during pregnancy? I am not sure if this question is too specific for this forum but I thought I'd ask your consideration. Please tell me if I have forgotten to give you certain information.
Thanks for your consideration,
Lisanne
I have a dataset which contains data about women using medication during pregnancy. For every drug I have the total duration of use and the exact start and stop dates of the drug (there can be 1, 2 or 3 episodes in time for the same drug as the drugs can be stopped and restarted). These dates often include periods of time before and after the pregnancy. Now I want to make a variable that describes the duration of the use ONLY during pregnancy; and I started writing a syntax as below but this doesn't always give me the right result when I check the total number of days manually.
I have the start date of the pregnancy (start_preg) and the date of birth (partus) as variables.
azt is the name of the drug, so azt_start1 is the date on which the drug was started first, an azt_stop1 is the date on which it was stopped for the first time. Then azt_stop3 for example is the 3rd time the drug was started (if this was the case). These different episodes are represented by a, b and c.
Furthermore, option 1 is the option that the drug was started before the pregnancy and it was stopped during pregnancy.
Option 2 is the option that the drug was started in pregnancy (so before the partus) and stopped after pregnancy.
Option 3 is the option that the drug was started in pregnancy and was also stopped in pregnancy.
Code:
gen duration_azt_preg_1a=(azt_stop1-start_preg) if (azt_start1<=start_preg&azt_stop1>start_preg&azt_stop1<=datepartus) gen duration_azt_preg_1b=(azt_stop2-start_preg) if (azt_start2<=start_preg&azt_stop2>start_preg&azt_stop2<=datepartus) gen duration_azt_preg_1c=(azt_stop3-start_preg) if (azt_start3<=start_preg&azt_stop3>start_preg&azt_stop3<=datepartus) gen duration_azt_preg_2a=(datepartus-azt_start1) if (azt_start1<datepartus&azt_start1>=start_preg&azt_stop1>datepartus) gen duration_azt_preg_2b=(datepartus-azt_start2) if (azt_start2<datepartus&azt_start2>=start_preg&azt_stop2>datepartus) gen duration_azt_preg_2c=(datepartus-azt_start3) if (azt_start3<datepartus&azt_start3>=start_preg&azt_stop3>datepartus) gen duration_azt_preg_3a=(azt_stop1-azt_start1) if (azt_start1>=start_preg&azt_stop1<=datepartus) gen duration_azt_preg_3b=(azt_stop1-azt_start2) if (azt_start1>=start_preg&azt_stop2<=datepartus) gen duration_azt_preg_3c=(azt_stop1-azt_start3) if (azt_start1>=start_preg&azt_stop3<=datepartus) egen duration_preg_final=rowtotal(duration_azt_preg_1a duration_azt_preg_1b duration_azt_preg_1c duration_azt_preg_2a
Thanks for your consideration,
Lisanne
Comment