LAG VALUE OF A VARIABLE

11 visualizaciones (últimos 30 días)
Saptorshee Chakraborty
Saptorshee Chakraborty el 1 de Ag. de 2018
Respondida: Parag el 28 de En. de 2025 a las 4:14
Hello, I want to have a lag value of variable X (PANEL of nature), but since Matlab does not accept different matrix size variables, what should I do. Variable is 4100*1 and lag of it is 3936*1.

Respuestas (1)

Parag
Parag el 28 de En. de 2025 a las 4:14
Hi, if you want to specifically handle the case where your lagged variable should be of size 3936x1, here's how you can do it:
To achieve a lagged vector of size 3936x1 from an original vector of size 4100x1, you need to determine how many observations to remove from the beginning of the original vector. You will need to create the lagged vector by shifting the original data down by one position, and then truncate both the original and lagged vectors to the desired length.
% Original data
X = rand(4100, 1); % Example data
% Create lagged variable
lagged_X = [NaN; X(1:end-1)];
% Determine the number of observations to keep
desired_length = 3936;
% Align the data
aligned_X = X(end-desired_length+1:end);
aligned_lagged_X = lagged_X(end-desired_length+1:end);
% Now both aligned_X and aligned_lagged_X are 3936x1
% You can proceed with your analysis
You can check this documentation for more detail

Categorías

Más información sobre Data Preprocessing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by