Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: create predicted values manually using matrices


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: create predicted values manually using matrices
Date   Mon, 23 Nov 2009 20:29:50 +0100

<>

It should be a task for -mata-, I guess:



*******
mata: mata clear

sysuse auto, clear
reg pr we f tr
capt which tomata
if _rc ssc inst tomata
tomata price weight foreign trunk

mata
	b=st_matrix("e(b)")'
	X=(weight, foreign, trunk, J(st_nobs(),1,1))
	y=price
	pred=X*b
	res=y-pred
	st_addvar("double", "pred")
	st_store(.,"pred", pred)
	st_addvar("double", "res")
	st_store(.,"res", res)
end
*******


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Joshua A.
Shindell
Sent: Montag, 23. November 2009 19:38
To: [email protected]
Subject: st: create predicted values manually using matrices

Hello, I would like to create predicted values by multiplying my vector
of estimated coefficients my the matrix of data used in the sample.

I use the following code to extract my vector of coefficients after the
regression:
reg depvar indepvar1 indepvar2

matrix coeffs=e(b)
matrix list coeffs
matrix coeffs = coeffs'
matrix list coeffs
 
I have tried using the following code to extract my data values:
local varnames : rownames(coeffs)
local k = rowsof(coeffs)
matrix values = J(`k',1,1)

Where I am looking for some help is with filling the matrix named values
with the values of each variable for each observation so I can use the
values and the estimated coefficients to generate a predicted value.

Any help is be greatly appreciated.

Josh Shindell



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index