I wonder if anyone could suggest a way to solve a problem when programming a nonlinear estimator using ML.
Consider a very simple model:
y=a0+a1*x+e
If I want to estimate this model with -nl- I could do something like the following:
Code:
sysuse auto, clear gen y=price/1000 gen x=mpg nl (y={a0}+{a1}*x), variables(x)
Code:
nl (y={a0}+{a1}*x), variables(x) margins, dydx(x)
Now assume I want to estimate the same model, and in a similar fashion using -ml-. This would be the equivalent code:
Code:
program myols args lnf a0 a1 lns qui: replace `lnf'=log(normalden($ML_y1,`a0'+`a1'*$ML_y2, exp(`lns'))) end ml model lf myols (a0: y x=) (a1:) (lns:), maximize ml display
So here is my question, is there an option within -ml- that would allow me to tell Stata that X is actually a dependent variable?
Or, is there a different / better way to estimate models of this type of model using ML.
The code I'm considering using, which seems very complicated is something like this:
Code:
program myols2 args lnf a0 a1 _x lns qui: replace `lnf'=log(normalden($ML_y1,`a0'+`a1'*`_x', exp(`lns'))) end constrain 1 _b[_x:x]=1 ml model lf myols2 (a0: y=) (a1:) (_x: =x, nocons) (lns:), maximize constrain(1) ml display margins, dydx(x) expression(predict(eq(#1))+predict(eq(#2))*predict(eq(#3)))
I would think there is an easier way to do this tho.
I understand this toy example could be simply done using a simple OLS regression, but the spirit of the problem is the same. And for those who are interested, Im estimating a nonlinear tobit model where the latent variable is a nonlinear function of the explanatory variables and estimated coefficients. Something like:
Code:
y*=(a+b*x1+c*x2)/(d+e*x2)
Fernando
0 Response to ML programming for Non linear regressions
Post a Comment