AFAIK -return- does not support an if condition. You may brunch your
program on a condition though. Instead of
return macro X=v1 if condition==true
return macro X=v2 if condition==false
write:
if condition==true return X=v1
else return X=v2
It was also in version 8, wasn't it?
Perhaps there are other changes needed to your program as well. Wait
for other comments.
Regards, Sergiy
On 8/11/08, Holland, Margaret <[email protected]> wrote:
> I am trying to convert an nl program from Stata 8 syntax to the Stata 9+ syntax. (I know how to include "version 8" to allow the Stata 8 program to run in Stata 9, but I want to learn the new syntax to be able to teach to the newest version.)
>
> I have been successful in running a very basic program, but I want to make it a little more complicated with "if" statements, as shown below in Stata 8 format (this one does run). When I try to convert to Stata 9 syntax, I'm not sure how to make the "if" statements work. The code below for Stata 9 does not run. Any suggestions appreciated.
>
> /*** Stata 8 code: this version runs ***/
> program drop _all
> clear
> use "Q:\temp.dta", clear
> set matsize 800
> version 8
> program nlprog
> version 8
>
> if "`1'" == "?" {
> global S_1 "a0 a1 c0"
> global a0=4.7 /* intercept for younger females */
> global a1=.1 /* slope for younger females */
> global c0=10 /* intercept for younger males */
> exit
> }
> replace `1'=($a0+$a1*Age) if Gender==1
> replace `1'=($c0+$a1*Age) if Gender==0
> end
>
> nl prog DCogFunction
>
>
> /*** Stata 9 code: this gives the following error when run
> /*** nlprogmlh returned 198
> /*** verify that nlprogmlh is a substitutable expression program
> /*** and that you have specified all options that it requires
> ***/
> program drop _all
> clear
> use "Q:\temp.dta", clear
> set matsize 800
> program nlprogmlh, rclass
> version 9
> syntax varlist(min=3 max=3) if
> local y : word 1 of `varlist'
> local x1 : word 2 of `varlist'
> local x2 : word 3 of `varlist'
> return local eq "`y'=({b2=4.7}+{b3=0.1}*`x2')" if `x1'==1
> return local eq "`y'=({b2}+{b3}*`x2'+1)" if `x1'==0
> end
>
> nl progmlh: DCogFunction Gender Age
>
>
> Thanks,
> Maggie
>
> *
> * 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/