Page 1 of 1
Display Matrices
Posted: Sun Oct 28, 2012 9:54 pm
by bearlotus
I would like to display the different matrices, from my model, how do I do so?
I would like to see (X'X)^-1, X'y, X'X
LINREG Y 1946:01 2011:01
# Constant X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
I have tried this for a more simple problem and have received this:
## MAT2. Matrices with Dimensions 15 x 2 and 15 x 2 Involved in * Operation
I am not exactly sure how to fix my code.
Thank you,
Re: Display Matrices
Posted: Mon Oct 29, 2012 9:36 am
by TomDoan
You can use the following as a guide:
Code: Select all
*
* Johnston & DiNardo, Econometric Methods, 4th edition
* Example 3.3 from page 75
*
data(unit=input,org=columns) 1 5 y x1 x2 x3
3 1 3 5
1 1 1 4
8 1 5 6
3 1 2 4
5 1 4 6
*
* The CMOM instruction computes cross product matrices. By including y
* and the three x variables, we have y'y, X'y and X'X, all in a single
* matrix. We can then use the %xsubmat function to pull out the pieces
* we need.
*
cmom
# y x1 x2 x3
compute xx=%xsubmat(%cmom,2,4,2,4)
compute xy=%xsubmat(%cmom,1,1,2,4)
compute b=%solve(xx,xy)
*
* And the (1,1) element of the cross product matrix is y'y, which we
* need to compute the sum of squared residuals
*
compute rss=%cmom(1,1)-%dot(b,xy)
disp "Multiple Regression Coefficients" b
disp "Sum of Squared Residuals" rss
*
* Same thing with means extracted. This is done using the "center"
* option on cmom. Of course, we leave the "x1" variable out of X when we
* do that.
*
cmom(center)
# y x2 x3
compute xx=%xsubmat(%cmom,2,3,2,3)
compute xy=%xsubmat(%cmom,1,1,2,3)
compute b=%solve(xx,xy)
disp "Multiple Regression Coefficients-Deviation Form" b