function Wx = panel_lags(x,W,N,T);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Usage: To construct spatial lags of desired independent variables in
% panel data. Is written with Kelly Pace's spatial panel functions in
% mind (www.spatial-statistics.com).
%
% Inputs:
% N - Number of cross sectional units
% T - Number of time periods
% W - N x N weight matrix
% x - (N*T x k) matrx of desired variables for spatial lags.
%
% Returns: N*T matrix of spatial lags of x.
%
% Written By:
% Justin M. Ross
% Department of Economics
% West Virginia University
% February 2008
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[junk k] = size(x);
for j=1:k;
for t=1:T;
t1=1+(t-1)*N;t2=t*N;
Wxc([t1:t2],j)= sparse(W)*x([t1:t2],j);
end;
end;
Wx = Wxc;