Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Problem with date variable in a macro


From   "Vladimir Vakhitov" <vvakhitov@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem with date variable in a macro
Date   Tue, 1 Apr 2008 13:51:07 -0400

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 <jgeorges@health.nyc.gov>:
> 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: jgeorges@health.nyc.gov
>  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
vvakhitov@gmail.com
*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index