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 13:23:44 +0100

Dear Joseph,

Thank you for drawing my attention to this, you right I was working
with a numeric variable, after using the decode command I ran the
substr command and it worked. Thanks again to Nick and Rich.

Best,
Mário

2013/7/14 Joseph Coveney <[email protected]>:
> Mario Jose wrote:
>
> 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?
>
> --------------------------------------------------------------------------------
>
> It seems that id_shar_cty is not a string variable.  Try typing
>
>     describe id_shar_cty
>
> or
>
>      confirm string variable id_shar_cty
>
> at the command line.
>
> Joseph Coveney
>
> . input str9 id_shar_cty
>
>      id_shar~y
>   1. AT9898_DE
>   2. PL9769_CZ
>   3. end
>
> .
> . generate str2 home_country = substr(id_shar_cty, 1, 2)
>
> . generate str2 host_country = substr(id_shar_cty, -2, .)
>
> .
> . list, noobs abbreviate(20)
>
>   +-------------------------------------------+
>   | id_shar_cty   home_country   host_country |
>   |-------------------------------------------|
>   |   AT9898_DE             AT             DE |
>   |   PL9769_CZ             PL             CZ |
>   +-------------------------------------------+
>
> .
> . exit
>
> end of do-file
>
> *
> *   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