Thank you, Vladimir. I used gen month1="`1'" which worked and then just
kept the variable as a string and was able to collapse by using it.
Josiane "Josie" Georges
Analyst, Liaison to the Division of Mental Hygiene
Policy & Planning
DOHMH
Tel: 212-788-5342
Fax: 212-788-5353
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Vladimir
Vakhitov
Sent: Tuesday, April 01, 2008 1:51 PM
To: [email protected]
Subject: Re: st: Problem with date variable in a macro
Josiane ,
You pass `1' to your program, where `1' takes values of 2004m? in
general. Then you run
gen month1 =`1',
which Stata understands as
gen month1 =2004m1
This is invalid. You may consider instead
gen month1="`1'"
Actually, the next line, with -destring- is also invalid and will not
get you what you want. See the syntax of that command.
If you need to get a month number from "2004m?" string, use -substr()-
function.
Vladimir.
2008/4/1, Josiane Georges <[email protected]>:
> I wrote the following macro, but got a "2004m1 invalid name" - r(198)
> error. I can't figure out what I did wrong. Any ideas on how I might
> debug this code?
>
> capture program drop auth_cld
>
> program define auth_cld
>
> {
> use auth`1'_id, clear
>
> gen month1 =`1'
>
> destring month1, generate month = m(month1) replace
>
> collapse (count) id, by (month)
>
> rename id num_chd
>
> label var num_chd "# unique children"
>
> format num_chd %9.0g
>
> save auth_cld`1', replace
>
> }
>
> end
>
> auth_cld 2004m1
>
> auth_cld 2004m2
>
> auth_cld 2004m3
>
> auth_cld 2004m4
>
> auth_cld 2004m5
>
> auth_cld 2004m6
>
>
> Josiane "Josie" Georges
> Analyst, Liaison to the Division of Mental Hygiene
> Policy and Planning
> NYC Department of Health and Mental Hygiene
> Tel: 212-788-5342
> Fax: 212-788-5353
> Email: [email protected]
> 125 Worth Street, Rm 624, CN #45
> New York, NY 10013
>
>
>
>
>
**********************************************************************
> The New York City Department of Health & Mental Hygiene is now
offering information important for the health of all New Yorkers. To
sign up for these new and valuable updates, log-on to our website at
http://www.nyc.gov/health/email and select the NYC DOHMH updates you'd
like to receive.
>
> IMPORTANT NOTICE: This email is meant only for the use of the
intended recipient. It may contain confidential information that is
legally privileged or otherwise protected by law. If you have received
this communication in error, please notify me immediately by replying to
this message and please delete it from your computer. Thank you for
your cooperation.
>
>
> *
> * 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/
>
--
__________________
Volodymyr Vakhitov
[email protected]
*
* 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/
**********************************************************************
The New York City Department of Health & Mental Hygiene is now offering information important for the health of all New Yorkers. To sign up for these new and valuable updates, log-on to our website at http://www.nyc.gov/health/email and select the NYC DOHMH updates you'd like to receive.
IMPORTANT NOTICE: This email is meant only for the use of the intended recipient. It may contain confidential information that is legally privileged or otherwise protected by law. If you have received this communication in error, please notify me immediately by replying to this message and please delete it from your computer. Thank you for your cooperation.
*
* 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/