options limwarn=0 ; supres smpl ; ? ? Program to center panel data variables (remove their means). ? TSP Version 4.4 ? BHH August 1998 ? const nt 20000 t 10 ; set n = nt/t ; ? ========= Synthetic Data Generation for Testing ================ smpl 1 nt ; dot (index=mean) 1-3 ; random (mean=mean) x. ; enddot ; msd x1-x3 ; ? ================================================================ ? smpl 1 nt ; ? ? Suppose you have 3 variables called x1 x2 x3 for 20000 obs on ? 2000 individuals, 10 years each. You want to remove the year ? means from each variable. ? ? Make a variable with 1,2,3,4,5,6,7,8,9,10 repeated 2000 times. ? trend (period=10) time ; ? ? This loop removes the means for each of the 10 years from the ? orginal data. ? do i = 1 to t ; ? Loop over years. select time=i ; ? Choose one year at a time. msd (noprint) x1-x3 ; ? Compute means for that year. unmake @mean xm1-xm3 ; ? Store the 3 means as scalars. dot 1-3 ; ? Loop over the 3 variables. xw. = x.-xm. ; ? Remove the mean for each of the variables. enddot ; msd (noprint) xw1-xw3 ; ? These should be mean zero. enddo ; smpl 1 nt ; ? Whole sample. msd xw1-xw3 ; ? This should still be mean zero. ? ? This section of the program shows how to remove individual means ? from the data. ? dot 1-3 ; ? ? Use the panel procedure (within estimator) to compute indiv-specific ? means. ? panel(t=t,notot,nobet,novar) x. c ; select time=1 ; unmake @fixed xfe. ; ? Make the fixed effect vector into a series. select time>1 ; xfe. = xfe.(-1) ; ? Replicate the fixed effects through the panel. select 1 ; ? Whole sample. xw. = x.-xfe. ; ? Remove the individual-specific mean. enddot ; msd xw1-xw3 ;