I am working on panel data as shown below:
I want to generate a time-dependent covariate for the total duration of past use up to time t. To do so, I thought I could use the "egen" command to sum up the values of curr_use up to time t, by id. However, I only managed to get the total duration of use for each subject (see below), i.e. a fixed-in-time variable, which is not what I need:
by id, sort: egen tot_duration = total(curr_use)
Could you please help me with the code? Thanks a lot!
0 Response to Help with time-dependent variable in longitudinal data
Post a Comment