Linear Regression with Dummy Interaction

조회 수: 12 (최근 30일)
FE
FE 2021년 7월 21일
댓글: Peter Perkins 2021년 7월 28일
Hi,
I am looking to estimate a linear regression in the following manner:
I want to estimate (a constant), the μ, and the ζ. I have coded both dummies as NxN matrixes containing 1 or 0 in the diagonal depending on the specif year, P(t),P(t-1) and A are vectors of length N.
I have tried to use fitlm by creating a table with all imputs.
fit2 = fitlm(tbl,'p~ d1+d2*pre_p+prod');
My error is the following:
"Predictor variables must be numeric vectors, numeric matrices, or categorical vectors."
I know that the issue lies in the coding of the dummy variable. My question is about implementation.
Thanks !
  댓글 수: 8
FE
FE 2021년 7월 27일
Hi,
Thank you for all the contributions and examples. I do believe I know why it does not work, what I don t understand is how to define the dummy such that it fits what I want to do.
I need two dummies:
the first is equal to one from 2000 Q1 - 2019 Q4 and else 0
the second is equal one from 1990 Q1 - 1999 Q4 and else 0
I don t see how fitlm "takes care" without proper definition.... so I am confused about implmentation.
Now what I did in the mean time, although extremly unelegant is code dummy 1 (equal to one from 2000 Q1 - 2019 Q4 and else 0) as a vector variable, and the other dummy 2 (equal one from 1990 Q1 - 1999 Q4 and else 0 ) I multiplied with my vector p(t-1) and then run my regression...
There should be a more straight forward way no?
Peter Perkins
Peter Perkins 2021년 7월 28일
If you use a categorical variable as a predictor in your model, fitlm will create dummy variables internally. I'm suire there are examples in the doc. You don't need to create dummy vars unless you want some non-standard coding. Maybe that's what you want. If so, creatre LOGICAL or NUMERIC dummy variables yourself. Based on the limited information you have provided, it appears that maybe you have been creating categorrical dummy variables.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by