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

st: RE: Doubt about Index


From   "Steichen, Thomas" <[email protected]>
To   <[email protected]>
Subject   st: RE: Doubt about Index
Date   Fri, 10 Jan 2003 14:59:44 -0500

Rodrigo -

Tell Stata that you are creating a string variable:

  . gen str2 rg1=substr(rg, 1, 2)

If you really want a numeric variable, use:

  . gen rg1=real(substr(rg, 1, 2))

You may also wish to strip any leading spaces... if so, use:

  . gen str2 rg1=substr(trim(rg), 1, 2)
or
  . gen rg1=real(substr(trim(rg), 1, 2))


Tom

> 
> 
> Hello friends of the list. I have a variable called rg which 
> contains a large amount of numbers that represent certain 
> income categories:
> 
>     1.       01.01.01
>     2.       01.02.01
>     3.       01.02.04
>     4.    01.01.02.01
>  and so on.  I wan to extract the first two numbers in order 
> to construct a new variable that tells me the main categories 
> of income, so I will have 01, 02, 03 and 04. My variable is a 
> string, so I think that I can use the substr function (gen 
> rg1=substr( rg, 1,2)), but I'm getting some error 109 that 
> talks about the inconsistency using numbers as strings. How 
> can I solve this?
> 
> Thanks for your time.
> 
> Rodrigo
> 
> 
> 
> *
> *   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/
> 

-----------------------------------------
CONFIDENTIALITY NOTE:  This e-mail message, including any
attachment(s), contains information that may be confidential,
protected by the attorney-client or other legal privileges, and/or
proprietary non-public information.  If you are not an intended
recipient of this message or an authorized assistant to an intended
recipient, please notify the sender by replying to this message and
then delete it from your system.  Use, dissemination, distribution,
or reproduction of this message and/or any of its attachments (if
any) by unintended recipients is not authorized and may be unlawful.

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