Statalist


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

RE: st: RE: create predicted values manually using matrices


From   "Joshua A. Shindell" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: create predicted values manually using matrices
Date   Tue, 24 Nov 2009 12:11:46 -0500

Padmakumar, thank you for  all of your help.  I verified everything and the solution you provided does exactly what I was looking for.

Best,

Joshua A. Shindell

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Padmakumar Sivadasan
Sent: Tuesday, November 24, 2009 10:41 AM
To: [email protected]
Subject: Re: st: RE: create predicted values manually using matrices

Joshua

What the code I suggest would do is to predict the coefficients using
period 1, and multiply the coefficients obtained with values in
period2 to obtain predicted values for period2. You can verify this
for the example using nlswork data and regressing ln_wage on hours

 For year 68, the coefficients are constant is 1.341017
The coefficient on hours is 0.0026844
And the predicted value for id=3 year=69 should be 1.341017 + (
.0026844 )*40 = 1.448392
You an verify that which is the same as the wage_hat value the code
generates for id=3 , year=69.

Note: 40 is the actual hours worked by id=3 in year=69.

Padmakumar

On Tue, Nov 24, 2009 at 8:52 AM, Joshua A. Shindell
<[email protected]> wrote:
> Padmakumar, thank you for your valuable suggestion.  I am wondering if the predict command you suggest will take the coefficient on hours estimated in period T and multiply it by the value of hours in t+1?
>
> Thank you for your help,
>
> Joshua A. Shindell
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Padmakumar Sivadasan
> Sent: Monday, November 23, 2009 6:01 PM
> To: [email protected]
> Subject: Re: st: RE: create predicted values manually using matrices
>
> I believe Joshua is using coefficients from period 1 regressions to
> predict the values of the dependent variable in period2.  Here is code
> that uses -predict- as Nick and Scott have suggested.
>
> tsset id period
> reg depvar indepvar1 indepvar2 if period==1
> predict depvar1 if period==2
>
> To loop this over multiple periods I would use a code similar to the following
>
> webuse nlswork, clear
> gen wage_hat=.
> forvalues x=68/70 {
> reg ln_wage hours if year==`x'
> predict temp if year==`x'+1
> replace wage_hat=temp if year==`x'+1
> drop temp
>                           }
>
>  Padmakumar
>
> On Mon, Nov 23, 2009 at 2:45 PM, Joao Ricardo F. Lima
> <[email protected]> wrote:
>>
>> Dear all,
>>
>> Sorry, but as I'm understanding the problem here is to use time series
>> operators and matrix... To use the time series operators you must
>> -tsset- your data first.
>>
>> clear all
>> input depvar indepvar1 indepvar2
>> 2 15 3
>> 3 23 5
>> 4 19 8
>> 2 32 6
>> 5 27 4
>> end
>>
>> gen time=_n
>> tsset time, yearly
>>
>> reg depvar indepvar1 indepvar2
>> gen cons=1
>> foreach var of varlist indepvar1 indepvar2 cons{
>>        gen f`var'=F.`var'
>> }
>> mkmat findepvar1 findepvar2 fcons, matrix(var_ind)
>> matrix B1=e(b)
>> matrix y_hat1 = var_ind*B1'
>> svmat y_hat1, names(depvar_hat)
>>
>> HTH,
>>
>> Joao Lima
>>
>>
>> 2009/11/23 Martin Weiss <[email protected]>:
>> >
>> > <>
>> >
>> > 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/
>> >
>>
>>
>>
>> --
>> ----------------------------------------
>> Joao Ricardo Lima, D.Sc.
>> Professor
>> UFPB-CCA-DCFS
>> Fone: +5538387264913
>> Skype: joao_ricardo_lima
>> ----------------------------------------
>>
>> *
>> *   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/
>
> *
> *   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/

*
*   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