Cox model: advice on constructing time varying exposure to drugs I am performing a survival analysis on medical registry data and would like to model drug exposure to estimate a continuous dose-response curve. I have drug data like this:

where ATC is the unqiue code of the drug, and DDD_pack is the number of days the pack of medication will cover assuming the person is taking the standard dose for that particular drug. Actual dose is unknown.
I'm having problems deciding the best way to construct the exposure variable for the dose response. My initial thoughts are to somehow include DDD pack as a time varying variable in a Cox model. However, I am unsure of how to decide on the time step / interval periods. For example, I could consider interval periods of length 90 days and compute the total DDD out of those 90 days as a proportion. Or I could chose 180 day intervals, or shorter ones. Is there a way to decide? There is also the problem that some people may actually be on a smaller or larger dose than the "standard" and hence the "real" DDD_pack might be somewhat less than or larger than the estimated values in the table. I thought perhaps of looking for patterns in the date dispensed column but it then got confusing since some people might be taking several drugs at once.
I would very much appreciate some advice for my analysis, in particlar how to chose the interval / period length for constructing the time depednant variable (drug exposure) for the Cox model.

For a Cox model, the statistical principle to keep in mind is how the model incorporates covariate values. At each event time, the model examines the covariate values in place at that event time for the individual with the event against the values at that event time for all individuals still at risk. There is no incorporation of prior exposure history into the model unless you construct a predictor that includes a measure of exposure history. The way you are thinking about the association of the drug with outcome thus determines how to present the drug information to the software. You have to make sure that the software knows, for all event times, your intended measure of drug exposure for all those still at risk. That determines how you need to structure your data set.
So the big question is what your intended measure of drug exposure should be. As you can't know whether the participants actually took the drug as prescribed, you will probably have to assume that all the prescribed drug was taken except for time periods that end in death or other terminal event. The case of id 659 that you show suggests that the net dose per day could be less than prescribed, as packs providing 33.3 or 16.7 days of drug lasted much longer than those periods, based on the intervals between refills. Should you divide the DDD_pack value by the number of days until the next refill, at least for time intervals that don't end in death? What's the best way to estimate drug exposure for time periods that end in death? That choice will be vey important and runs a risk of substantial bias if you just divide the last DDD_pack value by the number of days until death. Should there be some smoother average of drug exposure, or some measure of cumulative exposure?
Those considerations aren't strictly statistical. They need to be based on understanding of the subject matter. Discuss these issues with colleagues who are familiar with the details of the data and the underlying biomedical question you are addressing. Once you decide on a measure of estimated drug exposure that makes sense on that basis, then make sure that the values of your measure are available to the software, at each event time in the data set, for all individuals still at risk at that event time. That's typically done by the startTime, stopTime, event structure in the counting-process data format.
