Hi!
I am a Norwegian phd student exploring the effects of nocturnal road traffic noise exposure in children. One of the research questions is whether noise exposure at different ages (3, 5, 7, 8 years) is associated with body mass index measured at those same four ages (does the association between bmi and age depend on noise exposure?). I plan to use linear mixed model-analyses in Stata, with noise as a time-varying covariate (along with several other covariates).

To model noise as a time-varyng covariate, I split the noise variable into between persons and within persons effects:
First, generate a variable corresponding to each person’s mean score on the noise variable:

egen noise_personmean = mean(noise), by(id)

Center this variable by subtracting 50 to get a meaningful 0:

gen noise_bp = noise_personmean - 50 /*This variable now represents the between persons effect, the person mean of noise values*/

Next, I create a variable meant to represent the within person effect (each noise score's difference from the person's mean noise value):

gen noise_wp = noise - noise_personmean

Then, between and within person variables of noise is entered into the model. In addition, since the effect of noise_wp on bmi may differ for different values of noise_bp, an interaction term between noise_bp and noise_wp is also included. Since I am interested in whether the development of bmi with age depends on noise, I include an interaction term between noise_wp and age. If this interaction term significantly improves the model/changes the estimate for bmi_z, then this indicates that noise affects the bmi-age-association. Am I right? Does the syntax and interpretation make sense? Or should I choose another strategy?

mixed bmi_z noise_bp noise_wp c.noise_wp#c.noise_bp age_c ///
c.age_c#c.age_c c.age_c#c.noise_wp c.age_c#c.noise_bp i.gender ///
i.gender#c.noise_wp i.gender#c.noise_bp i.mat_education diet ///
i.physact || id: age_c, cov(unstr) mle vce(robust)

Best,
Kjell Vegard Weyde