The " " should be matched in my code.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 11 August 2008 17:39
To: [email protected]
Subject: st: RE: nl program conversion from Stata 8 to 9 or 10 including if statements
You make -if- compulsory and then ignore it. I classify that as a bug, but I doubt it is what is being complained about.
I am not up to speed with how to write newstyle -nl- programs, but these lines look
suspect:
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
You need perhaps
return local eq "`y'= ///
cond(`x1' == 1, ({b2=4.7}+{b3=0.1}*`x2'), ({b2}+{b3}*`x2'+1))
Nick
[email protected]
Holland, Margaret
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
�
*
* 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/