Statalist


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

RE: st: new string variable which has the formatted value of a variable


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: new string variable which has the formatted value of a variable
Date   Wed, 7 Jan 2009 15:47:09 -0000

Using -tostring- would be convenient for several variables, and it
certainly supports a -format()- option. (I am not clear why Jeph appears
uncertain on that.) 

But a lower-level route appears closer to what Ashim wants. That uses
the two-argument flavour of -string(,)-. 

To detect what format a variable has you go 

local fmt: format mynumvar 
gen svar = string(mynumvar, "`fmt'") 

Thus no magic is needed, just willingness to read the documentation. 

I don't understand why a string variable is needed here. Once a date has
been displayed in SMCL whether it came from a numeric variable or a
string variable is immaterial, but that is a separate issue. 

Nick 
[email protected] 

Jeph Herrin

I think -tostring- will work with the -format()- option.
Or, if you want to call mata you can use -sprintf()-.


Ashim Kapoor wrote:

> This is great. Will do part of what I what . I still need the magic
> command to do magic on dates.

> On Wed, Jan 7, 2009 at 5:21 PM, Neil Shephard <[email protected]>
wrote:
>> Not sure about dates, but for your second example you can do the
following....
>>
>> gen str magicj = string(round(j, .01))
>>

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index