Bookmark and Share

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]

Re: st: Command line syntax for optional and required numeric statements


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Command line syntax for optional and required numeric statements
Date   Sat, 12 Jan 2013 01:25:05 +0000

generate .o= oldage infertility

won't work. In general, see -help trace- to learn about debugging commands.

Nick

On Sat, Jan 12, 2013 at 12:46 AM, Stephen Cranney
<[email protected]> wrote:
> I tried discard (thanks for the head up--didn't know that could be an
> issue), but it still isn't working.
>
> I'm usually not wont to do this, but because I'm a little lost I'm
> just going to go ahead and post the whole command I'm trying to write,
> not because I expect anybody to spend the time to pick apart the whole
> code, but just because this has some problem in the beginning couple
> of lines that needs context. Everything within the syntax bracket is
> on one line, but was cut up because of the email.
>
> program birthsim, rclass
> version 11.2
> syntax [, startyear (real 2000) endyear(real 2100) birthday (real 9)
> birthmonth (real 1) birthyear (real 1987) marriageday (real 24)
> marriagemonth (real 8) marriageyear (real 2008) latestageatbirth(real
> 50) probabilityconceive(real .2) contraceptioneffectiveness(real 0)
> probabilitymiscarriage(real .25) fetallossinfertility(real 4)
> monthsofpostpartum(real 12)]
>
> *******************************************************************************************************
> *Setup data columns
> *******************************************************************************************************
> set more off
> set obs 1
> generate id=1
> generate age=25
> generate births= .f
>
> set more off
> forvalues bot = `startyear'(1)`endyear' {
>   gen age`bot' = age >= `bot'
> }
> replace age2012=age
> drop age
> reshape long age, i(id) j(year)
> egen month=group (year id)
> forvalues month = 1(1)12 {
>   gen month`month' = month >= `month'
> }
> egen group=group(year id)
> drop month
> reshape long month, i(group) j(newvar)
> drop month
> rename newvar month
> drop group
>
> *******************************************************************************************
> *Calculate birthday, age, and marriage day variable
> *******************************************************************************************
> generate birthdate=mdy(`birthmonth',`birthday',`birthyear')
> format birthdate %d
> generate marriagedate=mdy(`marriagemonth', `marriageday', `marriageyear')
> format marriagedate %d
> generate marriageage= (marriagedate-birthdate)/365.25
> generate day=1
> generate date=mdy(month, day, year)
> format day %d
> replace age=(date-birthdate)/365.25
> generate contraceptionnoneffectiveness= 1-`contraceptioneffectiveness'
> generate probabilityconceive2= `probabilityconceive'*
> contraceptionnoneffectiveness
> ************************************************************************************************************
> *Calculate probability of having a child, .i= postpartum infertility,
> generate .o= oldage infertility
> **********************************************************************************************************
> replace births= .a if age > `latestageatbirth'
> replace births= .a if age < marriageage
> replace births= rbinomial(1, probabilityconceive2) if births== .f
> generate miscarriage= rbinomial(1, `probabilitymiscarriage') if births== 1
>
> ******************************************************************************************
> *Create postpartum and post-abortive infertility.
> ******************************************************************************************
> local N = _N
> local  monthsofpostpartum =  12
> local monthsofpostmiscarriage= 7
> forvalues i = 1/`N' {
>         forvalues j= 1/`monthsofpostpartum' {
>               local k = `i' + `j'
>               local s= (`monthsofpostmiscarriage'-`j') + `i' + 1
>                 if births[`i']==1 & miscarriage[`i']==0 replace
> births= .p in `k'
>                 if births[`i']==1 & miscarriage[`i']==1 & `s'>1
> replace births= .m in `s'
>                 }
>         }
> sum births if births==1
> return scalar children= r(N)
> end
>
> On Fri, Jan 11, 2013 at 4:45 PM, [email protected] <[email protected]> wrote:
>> Are remembering to -discard- ?
>>
>> Sent with Verizon Mobile Email
>>
>>
>> ---Original Message---
>> From: [email protected]
>> Sent: 1/11/2013 4:42 pm
>> To: [email protected]
>> Subject: RE: st: Command line syntax for optional and required numeric statements
>>
>> Stephen,
>>
>> The following lines of code work fine for me, so you'll need to show us a little more of what you're doing.
>>
>> Incidentally, I thought the spaces after the -birthday- and -birthmonth- options would bite, but it works fine with them.
>>
>> - Elan
>>
>>
>> cap program drop testsyntax
>> program testsyntax
>>         syntax [, startyear(real 2000) birthday (real 9) birthmonth (real 1)]
>>
>>         di "`startyear'"
>>         di "`birthday'"
>>         di "`birthmonth'"
>> end
>> testsyntax
>> testsyntax, startyear(1981) birthday(5) birthmonth(1)
>>
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On Behalf Of Stephen Cranney
>> Sent: Friday, January 11, 2013 16:25
>> To: [email protected]
>> Subject: Re: st: Command line syntax for optional and required numeric statements
>>
>> I'm still getting the "invalid syntax" response. I tried making it all
>> optional and setting default values just to make it simpler. Now I
>> have
>>
>> syntax [, startyear(real 2000) birthday (real 9) !
>>  birthmonth (real 1)]
>>
>> I've seen various examples online that have this same format that don't
>> seem to be having the same problem, so I guess at this point my main
>> question is: in what situations would Stata return an "invalid syntax"
>> response based on something put in the "syntax" line in the ado file?
>> Setting trace on doesn't help because "invalid syntax" is
>> the first thing that pops up.
>>
>> Best,
>>
>> Stephen
>>
>> On Fri, Jan 11, 2013 at 3:09 PM, Nick Cox <[email protected]> wrote:
>>> The pattern
>>>
>>> latestageatbirth(default=50)
>>>
>>> isn't correct for options. See -help syntax-. Try e.g.
>>>
>>> latestageatbirth(real 50)
>>>
>>> Nick
>>>
>>> On Fri, Jan 11, 2013 at 7:31 PM, Stephen Cranney <[email protected]> wrote:
>>>
>>>> Apologies if this is simple, but I can't figure this out based on the
>>>> documentation.
>>>>
>>>> I'm writing an ado file and am trying to transfer all the macros I
>>>> reference inside the file to the command line. Some of the values I want to
>>>> make required, and some I wan!
>>  t to make optional, but with a default value
>>>> if the option is not t
>>
>> a
>> ken. All of the macros I want in the command line
>>>> are numeric.
>>>> A representative snippet of the code is below, based on what I've been able
>>>> to figure out from the documentation. It gives me an "invalid syntax"
>>>> response when I try to "birthsim, startyear(2000)...". It works when I do
>>>> it with args, but obviously that's much more cumbersome than syntax in this
>>>> context.
>>>>
>>>> program birthsim, rclass
>>>> version 11.2
>>>> syntax startyear(integer) endyear(integer)  [,latestageatbirth(default=50)
>>>> ]
>>>>
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index