On 08/10/2026 14:32, Sven Schreiber wrote:
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)

And if you have more than one variable, like in the original post:

<hansl>
loop foreach i Q_output PF_fuelprice LF_loadfactor
   series $i_cwc = $i - pmean($i)
endloop
</hansl>
-- 
-------------------------------------------------------
  Riccardo (Jack) Lucchetti
  Dipartimento di Scienze Economiche e Sociali (DiSES)

  Università Politecnica delle Marche
  (formerly known as Università di Ancona)

  r.lucchetti@univpm.it
  http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------