Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: editing of a variable content in stata


From   "Michael N. Mitchell" <[email protected]>
To   [email protected]
Subject   Re: st: editing of a variable content in stata
Date   Fri, 28 Jan 2011 11:30:18 -0800

Greetings

  I would give this a try...

generate firm1 = real(substr(firm,3,3))

The -substr()- function extracts the substring starting with the third digit, and extracting three digits, converting "IF789O" to "789", and then the -real()- function converts it into a number.

I hope that helps,

Michael N. Mitchell
Data Management Using Stata      - http://www.stata.com/bookstore/dmus.html
A Visual Guide to Stata Graphics - http://www.stata.com/bookstore/vgsg.html
Stata tidbit of the week         - http://www.MichaelNormanMitchell.com



On 2011-01-28 11.22 AM, [email protected] wrote:

I have a variable that is a code identifier for firms. it contains letters and
numbers. I would like to remove the first two digits  (these are letters) and
the last one from each firm identifier. Is this possible in stata?

Ex.

Firm   Code

irm1   If7890

Firm2 Fr5671

Firm3 er4560


I would like to have at the end:
Firm   Code

Firm1  789

Firm2  567

Firm3  456



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index