To provide a minimal example (I would like to use the solution of this in numerous applications), I am using the regress
function in MATLAB.
The data I have in MATLAB is (monthly) time series, however, some data points are missing at the start for certain series.
Lets say Y is a dependent variable in an arbitrary regression model and I would like to run 10 regression models,
$$Y_t=\alpha+X_{i,t-1}$$
I would therefore like to run 9 models, where the Y is the dependent variable and each model the explanatory variable changes from $X_2$ to $X_10$.
To be clear, I would like to run 9 models (see image),
The problem I am having is that I would like the first model that uses Y (i.e. data(:,1)
) and X2 (i.e. data(:,2) to use the first 1000 observations, but for the X3, there is 988 observations, so I would like to use 988 observations for Y and X3 when it does the regression.
In other questions, people have suggested changing the NaNs to 0's but this is not possible. EDIT (its obviously possible to change to zeros, but it is not possible for my model specification).
%Data
data = rand(1000,10); %add NaNs randomly at the start of the series.
%Regression
for ii = 2:10
b = regress(data(:,1),data(:,ii))
end
This question is different as it uses the regress function (yesterdays simple mean) also the answerer has provided lots of detail and a solution that actually works.