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: Create a variable equal to the first part of another variable


From   Mario Jose <[email protected]>
To   [email protected]
Subject   Re: st: Create a variable equal to the first part of another variable
Date   Sun, 14 Jul 2013 12:15:54 +0100

Nick and Rich thank you for your suh«ggestion. I have implemented as
you suggested
gen home_country=substr( id_shar_cty, 1,2)
gen host_country=substr("id_shar_cty", -2,.)
but from both I got the error message "type mismatch". The variable
id_shar_cty is the observation ID from where I want to extract the
other two variables. Am I doing something wrong?

2013/7/13  <[email protected]>:
> 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/

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index