⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 destring.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
字号:
{smcl}
{* 24feb2005}{...}
{cmd:help destring}, {cmd:help tostring}{right:dialogs:  {bf:{dialog destring}}  {bf:{dialog tostring}}}
{hline}

{title:Title}

{p2colset 5 22 24 2}{...}
{p2col :{hi:[D] destring} {hline 2}}Convert string variables to numeric and vice versa{p_end}
{p2colreset}{...}


{title:Syntax}

{phang}
Convert string variables to numeric variables

{p 8 29 2}
{cmd:destring}
[{varlist}]
{cmd:,}
{c -(}{opt g:enerate(newvarlist)}{c |}{opt replace}{c )-}
[{it:{help destring##destring_options:destring_options}}]

{phang}
Convert numeric variables to string variables

{p 8 27 2}
{cmd:tostring}
{varlist}
{cmd:,}
{c -(}{opt g:enerate(newvarlist)}{c |}{opt replace}{c )-}
[{it:{help destring##tostring_options:tostring_options}}]

{synoptset 23 tabbed}{...}
{marker destring_options}{...}
{synopthdr :destring_options}
{synoptline}
{p2coldent :* {opth g:enerate(newvarlist)}}generate {it:newvar_1}, ..., {it:newvar_k} for each variable in {varlist}{p_end}
{p2coldent :* {opt replace}}replace string variables in {it:varlist} with numeric variables{p_end}
{synopt :{cmdab:i:gnore("}{it:chars}{cmd:")}}remove specified non-numeric characters{p_end}
{synopt :{opt force}}convert non-numeric strings to missing values{p_end}
{synopt :{opt float}}generate numeric variables as type {opt float}{p_end}
{synopt :{opt percent}}convert percent variables to fractional form{p_end}
{synoptline}
{pstd}* Either {opt generate(newvarlist)} or {opt replace} is required.
{p2colreset}{...}

{synoptset 23 tabbed}{...}
{marker tostring_options}{...}
{synopthdr :tostring_options}
{synoptline}
{p2coldent :* {opth g:enerate(newvarlist)}}generate {it:newvar_1}, ..., {it:newvar_k} for each variable in {varlist}{p_end}
{p2coldent :* {opt replace}}replace numeric variables in {it:varlist} with string variables{p_end}
{synopt :{opt force}}force conversion ignoring information loss{p_end}
{synopt :{opth format(format)}}convert using specified format{p_end}
{synopt :{opt u:sedisplayformat}}convert using display format{p_end}
{synoptline}
{pstd}* Either {opt generate(newvarlist)} or {opt replace} is required.
{p2colreset}{...}


{title:Description}

{pstd}
{cmd:destring} converts variables in {varlist} from string to numeric.
If {it:varlist} is not specified, {cmd:destring} will attempt to convert all
variables in the dataset from string to numeric.  Characters listed in 
{opt ignore()} are removed.  Variables in {it:varlist} that are already numeric
will not be changed.  {cmd:destring} treats both empty strings "" and "." as
indicating sysmiss ({cmd:.}) and interprets the strings ".a", ".b", ...,
".z" as the extended missing values {cmd:.a}, {cmd:.b}, ..., {cmd:.z}; see
{help missing}.  Note that {cmd:destring} also ignores any leading or trailing
spaces so that, for example, " " is equivalent to "" and " . " is equivalent
to ".".

{pstd}
{cmd:tostring} converts variables in {it:varlist} from numeric to string.  The
most compact string format possible is used.  Variables in {it:varlist} that
are already string will not be converted.


{title:Options for destring}

{pstd}
Either {opt generate()} or {opt replace} must be specified.  With either
option, if any string variable contains non-numeric characters not specified
with {opt ignore()}, then no corresponding variable will be generated.  Nor
will that variable be replaced, unless {opt force} is specified.

{phang}
{opth generate(newvarlist)} specifies that a new variable be created for each
variable in {varlist}.  {it:newvarlist} must contain the same number of new
variable names as there are variables in {it:varlist}.  If {it:varlist} is not
specified, {opt destring} attempts to generate a numeric variable for each
variable in the dataset; {it:newvarlist} must then contain the same number of
new variable names as there are variables in the dataset.  Any variable labels
or characteristics will be copied to the new variables created.

{phang}
{opt replace} specifies that the variables in {it:varlist} be converted to
numeric variables.  If {it:varlist} is not specified, {cmd:destring} attempts
to convert all variables from string to numeric.  Any variable labels or
characteristics will be retained.

{phang}
{cmd:ignore("}{it:chars}{cmd:")} specifies non-numeric characters to be
removed.  If any string variable contains any non-numeric characters other
than those specified with {opt ignore()}, no action will take place for that
variable unless {opt force} is also specified.

{phang}
{opt force} specifies that any string values containing non-numeric
characters, in addition to any specified with {opt ignore()}, be treated as
indicating missing numeric values.

{phang}
{opt float} specifies that any new numeric variables be created initially as
type {opt float}.  The default is type {opt double}; see {help data types}.
{cmd:destring} attempts automatically to compress each new numeric variable
after creation.

{phang}
{opt percent} removes any percent signs found in the values of a variable, and
all values of that variable are divided by 100 to convert the values to
fractional form.  {opt percent} by itself implies that the percent sign 
"{cmd:%}" is an argument to {opt ignore()}, but the converse is not true.


{title:Options for tostring}

{pstd}
Either {opt generate()} or {opt replace} must be specified.  If converting any
numeric variable to string would result in loss of information, no variable
will be produced unless {opt force} is specified.  For more details, see
{opt force} below.

{phang}
{opth generate(newvarlist)} specifies that a new variable be created for each
variable in {varlist}.  {it:newvarlist} must contain the same number of new
variable names as there are variables in {it:varlist}.  Any variable labels
or characteristics will be copied to the new variables created.

{phang}
{opt replace} specifies that the variables in {it:varlist} be converted to
string variables.  Any variable labels or characteristics will be retained.

{phang}
{opt force} specifies that conversions be forced even if they entail loss of
information.  Loss of information means one of two
circumstances:  (1) The result of 
{cmd:real(string(}{it:varname}{cmd:, "}{it:format}{cmd:"))} is not equal to
{it:varname}, i.e., the conversion is not reversible without loss of
information; (2) {opt replace} was specified, but a variable has associated
value labels.  In circumstance (1), it is usually best to specify 
{opt usedisplayformat} or {opt format()}.  In circumstance (2), value labels
will be ignored in a forced conversion.  Note that {helpb decode} is the
standard way to generate a string variable based on value labels.

{phang}
{opt format(format)} specifies that a numeric format as an argument to the
{opt string()} function, which controls the conversion of the numeric variable
to string.  For example, a format of {opt %7.2f} specifies that numbers are to
be rounded to 2 decimal places before conversion to string.  See
{help functions} and {helpb format}.  {opt format()} cannot be specified
with {opt usedisplayformat}.

{phang}
{opt usedisplayformat} specifies that the current display format be used for
each individual variable.  For example, this option could be useful when using
U.S. social security numbers.  {opt usedisplayformat} cannot be specified with
{opt format()}.


{title:Examples}

{phang}{cmd:. destring, replace}

{phang}{cmd:. destring price, generate(price2)}

{phang}{cmd:. destring price weight, generate(price2 weight2) ignore("$ ,%")}

{phang}{cmd:. destring price weight, generate(price2 weight2) ignore("$, %") float}

{phang}{cmd:. destring price weight, replace ignore("$ ,%") float force}

{phang}{cmd:. destring price, replace ignore("%, $") force}

{phang}{cmd:. destring percent, generate(percent2) i("%") force percent}


{phang}{cmd:. tostring a b c, replace}

{phang}{cmd:. tostring a b c, replace usedisplayformat}

{phang}{cmd:. tostring price, generate(price2)}

{phang}{cmd:. tostring gear_ratio, generate(s_gear_ratio) format(%7.2f) force}

{phang}{cmd:. ds, has(char tostring)}


{title:Also See}

{psee}
Manual:  {bf:[D] destring}

{psee}
Online:  {helpb egen}, {helpb encode},
{help functions}, {helpb generate}, {helpb split}
{p_end}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -