Coputation of fitted values
Moderators: EViews Gareth, EViews Moderator
Coputation of fitted values
Dear Moderators and Eviews users,
I am trying to estimate a 2SLS in two stages, rather using the Eviews' built in option. In the first stage, I regress my endogenous variable Femaledir on all exogenous variables and the instrument, as suggested. How do I then compute fitted values for Femaledir from the output of this first stage estimation, that I can then use in the second stage to replace femaledir? Thank you very much!!
I am trying to estimate a 2SLS in two stages, rather using the Eviews' built in option. In the first stage, I regress my endogenous variable Femaledir on all exogenous variables and the instrument, as suggested. How do I then compute fitted values for Femaledir from the output of this first stage estimation, that I can then use in the second stage to replace femaledir? Thank you very much!!

 Nonnormality and collinearity are NOT problems!
 Posts: 3180
 Joined: Wed Sep 17, 2008 2:25 pm
Re: Coputation of fitted values
Use the fit command.
As you probably know, estimating 2sls manually in two stages does not give the correct standard errors.
As you probably know, estimating 2sls manually in two stages does not give the correct standard errors.
Re: Coputation of fitted values
Thank you Startz! Do you suggest that the secondstage estimation will be incorrect? The reason I fell for the manual estimation is because the Eviews' built in option returns negative Rsquared and some menaingless results, compared to standard OLS estimation. This is why I decided to try manual estimation. Is there any way to correct the standard errors? And can you please be more specific as to the sintax for fit? Say, my equation name is eq02, how do I than generate fitted values for the dependent variable from that equation? Thanks a lot in advance, much appreciated.

 Nonnormality and collinearity are NOT problems!
 Posts: 3180
 Joined: Wed Sep 17, 2008 2:25 pm
Re: Coputation of fitted values
oksanakim wrote:Thank you Startz! Do you suggest that the secondstage estimation will be incorrect? The reason I fell for the manual estimation is because the Eviews' built in option returns negative Rsquared and some menaingless results, compared to standard OLS estimation. This is why I decided to try manual estimation. Is there any way to correct the standard errors? And can you please be more specific as to the sintax for fit? Say, my equation name is eq02, how do I than generate fitted values for the dependent variable from that equation? Thanks a lot in advance, much appreciated.
There is nothing at all wrong with a negative Rsquared.
The fit command is documented in the help system.
It's fine to do 2SLS manually for fun, but the way to be sure that coefficients, standard errors, Rsquared, etc. are correct is to see if your results match EViews. There's nothing to "fix" by doing it manually.
Re: Coputation of fitted values
Thank you again! I have a related quesiton/observation. I also estimated Heckit in Eviews and then did the same manually: I estimated the firststage probit model, then computed Inverse mills ratio using one of the commands provided in the forum earlier, and then used it as a dependent variables in the second stage estimation with OLS. The results of the manual derivation versus Heckit are overwhelmingly different: in Heckit the coefficients of interest are insignificant, whereas in the manual derivations they are highly significant. The program I used to compute inverse mills ratio was:
eq01.makeresid ordinary
eq01.makeresid(g) general
eq01.fit yprob
series imills2 = general*(1yprob)/ordinary
In the previous versions of Eviwes, there was no Heckit option and I used to compute Imills ratio manually using the command above. But now what's wrong with the manual estimation and why are the two so different? This is striking. I can provide an output for the two estimations  manual and heckit  if you are interested. Thanks a lot.
eq01.makeresid ordinary
eq01.makeresid(g) general
eq01.fit yprob
series imills2 = general*(1yprob)/ordinary
In the previous versions of Eviwes, there was no Heckit option and I used to compute Imills ratio manually using the command above. But now what's wrong with the manual estimation and why are the two so different? This is striking. I can provide an output for the two estimations  manual and heckit  if you are interested. Thanks a lot.

 Nonnormality and collinearity are NOT problems!
 Posts: 3180
 Joined: Wed Sep 17, 2008 2:25 pm
Re: Coputation of fitted values
I'm afraid I haven't done a Heckit in a long time.
Re: Coputation of fitted values
I see... Is the command to compute the Inverse Mills raito at least correct? Thanks Startz.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Coputation of fitted values
Somewhat obvious question  but when using the built in method of estimation, did you use twostep or ML?
Follow us on Twitter @IHSEViews
Re: Coputation of fitted values
I used Heckam twostep option.
Re: Coputation of fitted values
I also wonder why a coefficient on Inverse Mills ratio is not reported when Heckit is used. It's kind of a big deal to discuss whether or not it is significant, at least for academic publications. Thank you.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Coputation of fitted values
It was our view that the literature had moved away from the twostep model, and only included it for completeness. There's really no reason to estimate using the twostep method other than as a teaching tool (same argument as twostage least squares).
Having said that  no idea why your estimation is not matching the built in. Without seeing exactly what you did, it is hard to say.
Having said that, here's an example of manual twostep compared with built in using the MROZ workfile.
Having said that  no idea why your estimation is not matching the built in. Without seeing exactly what you did, it is hard to say.
Having said that, here's an example of manual twostep compared with built in using the MROZ workfile.
Code: Select all
smpl @all
equation select.binary inlf age age^2 faminc kids educ
select.fit(i) xbhat
series imills = @dnorm(xbhat)/@cnorm(xbhat)
series delt = imills*(imills+xbhat)
smpl if inlf = 1
equation response.ls wage exper exper^2 educ city imills
scalar sigma = @sqrt(response.@ssr/response.@regobs + @mean(delt)*response.c(5)*response.c(5))
scalar rho = response.c(5)/(sigma)
group wg exper exper^2 educ city imills
matrix w = @convert(wg)
group zg age age^2 faminc kids educ
matrix z = @convert(zg)
stom(delt, dvec)
sym delta = @makediagonal(dvec)
sym mid1 = @identity(@rows(delta)) rho*rho*delta
sym wrw = @transpose(w)*mid1*w
sym V = select.@coefcov
sym Q = @transpose(w)*delta*z*v*@transpose(z)*delta*w*rho*rho
sym invww = @inverse(@transpose(w)*w)
sym cov = sigma*sigma*invww*(wrw + q)*invww
smpl @all
equation builtin.HECKIT(2STEP) WAGE EXPER EXPER^2 EDUC CITY @ INLF AGE AGE^2 FAMINC KIDS EDUC
show response
show builtin
Follow us on Twitter @IHSEViews
Re: Coputation of fitted values
Not really, these models are widely used in academic publications, some streams of research assume they are used no matter what. Thank you for the example of the program. Please confirm, is the below program to compute Inverse Mills ratio correct? Thanks a bunch
eq01.makeresid ordinary
eq01.makeresid(g) general
eq01.fit yprob
series imills2 = general*(1yprob)/ordinary
eq01.makeresid ordinary
eq01.makeresid(g) general
eq01.fit yprob
series imills2 = general*(1yprob)/ordinary

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Coputation of fitted values
Heckman selection is widely used  but aren't most estimated with the superior ML method rather than 2Step?
I'm not sure if your calculation is correct, but I'm pretty sure the one in the code I posted is, and matches the wikipedia definition of the ratio.
https://en.wikipedia.org/wiki/Mills_ratio
I'm not sure if your calculation is correct, but I'm pretty sure the one in the code I posted is, and matches the wikipedia definition of the ratio.
https://en.wikipedia.org/wiki/Mills_ratio
Follow us on Twitter @IHSEViews

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11411
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Coputation of fitted values
Thinking about it a bit, yes your code will compute it correctly too.
You can confirm this by adding this code to the bottom of my code:
You can confirm this by adding this code to the bottom of my code:
Code: Select all
select.makeresid ordinary
select.makeresid(g) general
select.fit yprob
series imills2 = general*(1yprob)/ordinary
show imills2 imills
Follow us on Twitter @IHSEViews
Re: Coputation of fitted values
Thank you, the two codes return the same results for Imills series.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests