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]

st: Breaking one string variable into several new variables


From   Anna Rakhman <[email protected]>
To   [email protected]
Subject   st: Breaking one string variable into several new variables
Date   Wed, 24 Feb 2010 17:22:31 -0500

Dear Statalist,

I have the following issue I was hoping you could help with.  I've imported
data from a .txt file and no matter how I import it, I always end up with
one variable while I really need 6 different variables.

This is what my file now looks like now (this is the first 4 observations of
variable v1, the only variable in the dataset):

industry1                     industry1_def                   industry2
          industry2_def            year              value
1                                oilseed farming                 100
              cotton farming          2000              .1
2                                logging                             200
                  iron ore mining         2000              .2
3                                blah and blah and blah       300
           yata, yata                 2000              .3

This is a made-up example, but as you can see, the problem is that each
column should be a separate variable.

I've tried using gen split1=(v1,1), gen split2=(v1,-1) and gen
split3=(v1,-2) to get industr1, value, and year as separate variables, but
I'm not sure how to get industry2 as a separate variable because it is not a
fixed number of words from either end of the string.

Any suggestions?

Thanks!
Anna

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