Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: do-file arguments acting weird


From   "Cohen, Elan" <cohened@upmc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: do-file arguments acting weird
Date   Wed, 1 Aug 2012 17:51:02 +0000

Formats can only be applied to numeric items, which macro 'a' is not.  Of course, you could always convert it to numeric, then apply the format:

loc a 16jun2012
loc anum = date("`a'","DMY")
di %tdDDMonCCYY `anum'
di %tdCCYY-DD-NN `anum'

HTH,

- Elan


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of tashi lama
Sent: Wednesday, August 01, 2012 12:36
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: do-file arguments acting weird

Sorry guys. I think I found the problem. I have tokenize used in between the dofiles. So, `1', which would have been 1st argument becomes 1st string of macro after tokenize. Still pondering about the 2nd question though. 
----------------------------------------
> From: ltashi32@hotmail.com
> To: statalist@hsphsun2.harvard.edu
> Subject: st: do-file arguments acting weird
> Date: Wed, 1 Aug 2012 16:12:12 +0000
>
>
> Hello all,
> 1. Could someone look into this and educate me? I am kind of lost. I am just copying portion of my dofile here but it should be enough for my question.
> clear
> set more off
> .......
> if "`graph_type'"=="line" {
> if "`measure'"=="peer" {
> args graph_type is_internal firm_id start_date end_date measure peer_id lag lead //there are 9 arguments
> .........
> .........
> if "`10'"=="" {
> tsline hits
> exit
> }
> else {
> tsline hits1 hits2
> exit
> }
>
> when I execute do file stata always executes the first if(tsline hits) regardless of 9 or 10 arguments although in theory, stata has to execute 2nd if(tsline hits1 hits2) in the case of 10 arguments. However,
> if I modify my argument list
> args graph_type is_internal firm_id start_date end_date measure peer_id lag lead zoom //zoom is the 10th argument which was absent above
> ............
> ...........
> if "`zoom'"=="" {
> tsline hits
> exit
> }
> else {
> tsline hits1 hits2
> exit
> }
>
> this time stata does it right. Does anyone have any clue?
>
> 2. If I have a variable date with date in format %tdDDMonCCYY, I have no problem changing to other formats using ( format date %tdCCYYDDMON or format I desire). However, if I have a date in a macro, how can I change the display format. For eg.
>
> local a 01jan2011
> di "`a'"
> 01jan2011
> if I want `a' in 2011-01-01, then
> format `a' %tdCCYY-DD-NN (of course stata isn't happy)
>
> Any idea?
>
> Thanx always.
> *
> * 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/


*
*   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/


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