Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Constrained Nonlinear Least Squares


From   Xiaofei Yu <xiaofeiyu.stata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Constrained Nonlinear Least Squares
Date   Fri, 14 Oct 2005 12:22:50 -0700

Hi everyone,

Can STATA actually do constrained nonlinear-squares regression of two
equations, (A) and (B) below, when one of the equations involves a
condition that generates an indicator variable to be used in (A)?

I have the following system of equations.  The endogenous and
indicator variable, Indi(t), is used as an explanatory variable in
(A), but the parameters defining Indi(t) need to be estimated from
(A).

The model and the constraint need to be estimated simultaneously since
beta and gamma that define Indi need to be estimate from (A).


I run a nl command and guess some initial values; however, the results
don't seem to be correct intuitively.  I'd appreciate your inputs and
if you can shed some lights on this.



(A) The regression model:

R(t) - R(t-1) =3D [lamdau*Indi(t)+lamdad*(1-Indi(t)]*[beta*rate(t) +
gamma - R(t-1)] + error(t)


(B) The constraint that defines the indicator variable I(t) above:

I(t)  =3D  1 if beta*rate(t) + gamma - R(t-1) > 0
        =3D  0 if beta*rate(t) + gamma - R(t-1) < 0



I coded the following commands in STATA:
cap program drop nlratechg
Program nlratechg
          if "`1'"=3D=3D"?" {
          global S_A "lamdau lamdad beta gamma"
          global lamdau=3D1
          global lamdad=3D1
          global beta=3D1
          global gamma=3D1
          exit
          }
gen Indi=3D1 if ($beta*rate+$gamma - L.R) > 0
replace Indi=3D0 if ($beta*rate+$gamma - L.R) < 0
replace `1'=3D($lamdau*Indi + $lamdad*(1-Indi))*($beta*rate + $gamma =96 L.=
R)
drop Indi
end

nl ratechange dR

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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