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: Create a variable equal to the first part of another variable
From
[email protected]
To
[email protected]
Subject
Re: st: Create a variable equal to the first part of another variable
Date
Sat, 13 Jul 2013 12:12:27 -0400 (GMT-04:00)
assuming that, as in your example, the first and last parts are 2 characters each:
gen share=substr(ID,1,2)
gen subs=substr(ID,-2,.)
Rich
-----Original Message-----
>From: Mario Jose <[email protected]>
>Sent: Jul 13, 2013 10:31 AM
>To: [email protected]
>Subject: st: Create a variable equal to the first part of another variable
>
>Dear All,
>
>I have a database where the ID is like this AT9898_DE. This specific
>observation is a subsidiary located in the country DE owned by the
>shareholder 9898 located in the country AT. I would like to create two
>variables: one consisting the country of the sharehodler (AT in the
>example) and another equal to the country of the subsidiary (DE).
>
>I would be grateful for suggestions on how to generate from the ID
>variable these two variables. In the end I would have my
>observations/databse like this:
>
>ID Share_country Subs_country
>AT9898_DE AT DE
>PL9769_CZ PL CZ
>.... . ... ...
>
>I would appreciate any help.
>
>Best regards,
>MJ
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/