Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Francesca Colantuoni <f.colantuoni9@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: macro `if' in nonlinear least squares |

Date |
Thu, 2 May 2013 11:55:24 -0400 |

Thanks Marteen. Actually, it appears to me that the macro `if' was not defined previously with some restrictions: program nlces version 12 syntax varlist(min=3 max=3) [aw fw iw] if, at(name) local logout: word 1 of `varlist' local capital: word 2 of `varlist' local labor: word 3 of `varlist' // Retrieve parameters out of at tempname b0 rho delta scalar `b0' = `at'[1,1] scalar `rho' = `at'[1,2] scalar `delta' = `at'[1,3] // Some temporary variables tempvar kterm lterm generate double `kterm' = `delta'*`capital'^(-1*`rho') `if' generate double `lterm' = (1-`delta')*`labor'^(-1*`rho') `if' // Now fill in dependent variable replace `logout' = `b0' - 1/`rho'*ln(`kterm'+`lterm') `if' end I am new to programming, so... Thanks a lot guys for your directions! Francesca On Thu, May 2, 2013 at 11:48 AM, Francesca Colantuoni <f.colantuoni9@gmail.com> wrote: > Thanks Nick for your response. I did not find this explanation in > [U]nl, but I have not tried -help nl-. > If I understand correctly, unless I have other rescrictions for > subsamples, the `if' will not matter, but it's part of the routine. > > Francesca > > On Thu, May 2, 2013 at 11:33 AM, Nick Cox <njcoxstata@gmail.com> wrote: >> See the help and manual entry for -nl-. The short answer is that for >> generality a program must have a way of working with subsets. If you >> are all the data, `if' is empty and no restriction is applied. >> >> "Function evaluator programs must accept a varlist, an if exp, and an >> option named at() >> that accepts the name of a matrix. It may optionally accept >> weights as well. Unlike >> substitutable expression programs, a function evaluator program is >> not declared to be >> r-class. The outline of a nlfunc_prog program is >> >> program nlfunc_prog >> version 10 >> syntax varlist [aw fw iw] if, at(name) >> local lhs: word 1 of `varlist' >> local rhs: subinstr local varlist "`lhs'" "", word >> (evaluate the function at at matrix) >> replace `lhs' = <the function values> `if' >> end >> >> When evaluating your function, remember to restrict the estimation >> sample by using `if'." >> Nick >> njcoxstata@gmail.com >> >> >> On 2 May 2013 16:27, Francesca Colantuoni <f.colantuoni9@gmail.com> wrote: >>> I am programming a nonlinear least square regression, and I am trying >>> to find the best way to do it based on variuos examples that I found >>> online. >>> >>> In the following code, I have trouble understanding what stata does >>> with the macro `if' at the end of the generate command. Would anybody >>> clarify that for me? I could not find an explanation for this use of >>> "if" in either [P] or [U] manual (or Google). >>> >>> // Some temporary variables >>> tempvar kterm lterm >>> generate double `kterm' = `delta'*`capital'^(-1*`rho') `if' >>> generate double `lterm' = (1-`delta')*`labor'^(-1*`rho') `if' >>> >>> // Now fill in dependent variable >>> replace `logout' = `b0' - 1/`rho'*ln(`kterm'+`lterm') `if' >>> >>> Best Regards, >>> Francesca >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: macro `if' in nonlinear least squares***From:*Maarten Buis <maartenlbuis@gmail.com>

**References**:**st: macro `if' in nonlinear least squares***From:*Francesca Colantuoni <f.colantuoni9@gmail.com>

**Re: st: macro `if' in nonlinear least squares***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: macro `if' in nonlinear least squares***From:*Francesca Colantuoni <f.colantuoni9@gmail.com>

- Prev by Date:
**Re: st: macro `if' in nonlinear least squares** - Next by Date:
**Re: st: Time-series operators and -outreg-** - Previous by thread:
**Re: st: macro `if' in nonlinear least squares** - Next by thread:
**Re: st: macro `if' in nonlinear least squares** - Index(es):