Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: mata problem: convert sting to real


From   "Jann Ben" <[email protected]>
To   <[email protected]>
Subject   st: mata problem: convert sting to real
Date   Mon, 8 Aug 2005 23:06:50 +0200

Hi,

I have a Mata problem that drives me crazy.

Some weeks ago I posted a mata function called -realofstr()- 
on SSC. The function can be used to convert string elements 
into numeric values. See -ssc d mf_realofstr-.

I don't like -realofstr()- because it makes use of Stata 
commands. The task - converting sting to real - is so basic 
that I think there should be a genuine mata solution without 
any Stata in it.

Note that the reverse - real to string - is a built-in
Mata function. See -help mata strofreal()-. The fact that 
official Mata has a -strofreal()- function but not a 
-realofstr()- function makes me suspect that the latter is 
not really needed. There must be some ridiculously simple 
way to covert string to real, but I just don't see it. Can
anyone help me? Bill?

Furthermore, note that, naturally, mata can do the conversion 
of string to real in interactive mode. For example, if you 
type

 : r = 1.2

mata sees the string "1.2" and thinks: "Well this must be a 
number, so let's store it as a real scalar." But how can the
conversion be done none-interactively?

Thanks in advance,
ben 


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