Dear Statalist
This is my first post and I'm afraid I'm not a very experienced programmer and I can't find similar answers online but I really hope one of you will be able to help me.
I am doing an analysis looking at renal function (eGFR) during exposure in different drug categories and I would normally do this by looking at eGFR slopes using eGFR as a variable in a mixed effects model or OLS ie. regress egfr time i.drug
The dataset is currently set up similar to this where eGFR is time updated per month (although for the purposes of the slope coefficient, this is generated as change in eGFR per year). There are 50,000 individual IDs with between 1 and 500 eGFR values in the dataset.
etc..
Although this gives me an estimate of the overall eGFR slope, I am interested in looking at generating a time updated slope variable where there is value for the slope at each time point. Each slope value at each date for each subject would include all the eGFR measurements up to and including that time point.
My problem is generating this time updated slope variable; I would like to use linear regression (or indeed, a slope equation) to generate the slope and use this as my new variable but I don't know how to create a loop to do this, or incorporate the result in my dataset.
I would be very grateful for any advice
Many thanks
Lisa
This is my first post and I'm afraid I'm not a very experienced programmer and I can't find similar answers online but I really hope one of you will be able to help me.
I am doing an analysis looking at renal function (eGFR) during exposure in different drug categories and I would normally do this by looking at eGFR slopes using eGFR as a variable in a mixed effects model or OLS ie. regress egfr time i.drug
The dataset is currently set up similar to this where eGFR is time updated per month (although for the purposes of the slope coefficient, this is generated as change in eGFR per year). There are 50,000 individual IDs with between 1 and 500 eGFR values in the dataset.
id | egfr | drug | date |
1 | 75 | 1 | 1nov2000 |
1 | 75 | 2 | 1dec2000 |
1 | 64 | 2 | 1jan2001 |
1 | 64 | 2 | 1feb2002 |
2 | 90 | 1 | 1jul2004 |
Although this gives me an estimate of the overall eGFR slope, I am interested in looking at generating a time updated slope variable where there is value for the slope at each time point. Each slope value at each date for each subject would include all the eGFR measurements up to and including that time point.
My problem is generating this time updated slope variable; I would like to use linear regression (or indeed, a slope equation) to generate the slope and use this as my new variable but I don't know how to create a loop to do this, or incorporate the result in my dataset.
I would be very grateful for any advice
Many thanks
Lisa