Am 27.09.2026 um 14:33 schrieb Ramki S:
When working with panel data, I need to create the cwc (centered within cluster) variables quickly. Although there is "add time mean.." will do exaclty this job in creating L2 variable, I have to do one more step to create the cwc variable. Can we have some function to do the both? I am using the terminology used in multi-level models. 

series Q_output_L2 = pmean(Q_output)
series Q_output_cwc  = Q_output - Q_output_L2

Two remarks here. First, if that's what you mean by "quickly", you could simply write this in one line as:

series Q_output_cwc = Q_output - pmean(Q_output)

Secondly, this within-calculation is basically the fixed-effects regression without any other regressors. So you could also do (untested):

panel Q_output const
series Q_output_cwc = $uhat

So far it didn't seem worthwhile to add more syntactic sugar natively to obtain the same result. I guess the PanelTools package might be a natural place to have that, in the medium term, if at all. 

cheers

sven