Statalist


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

Re: st:how to connect a variable's value with another variable's name


From   Tim Wade <wadetj@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st:how to connect a variable's value with another variable's name
Date   Wed, 25 Mar 2009 21:25:09 -0400

Mandy, how about:

gen str4 main_location=""

forvalues i=1/4 {
 replace main_location=location`i' if main_firm==`i'
}

Tim


On Wed, Mar 25, 2009 at 4:04 PM, Mandy fu <mandy.fu1@gmail.com> wrote:
> Hi all,
>
> I'm not sure how to connect a variable's value with another variable's name.
> My data set is about characteristics of all the firms  for which
> respondents  work in a year. Variable "main_firm" (whose value is
> 1,2,3,4)  provides  the number of the firm  where the worker works for
> the longest time in that year. the variables location1-4 give the
> location of each firm the respondent works according to the time
> sequence from the earliest to the most recent. It looks like follows:
> -------------------------------------------------------------------------------------
> workerID  main_firm   location1 location2  location3  location4
>      1           2              MA          NY                  NJ
>     MA
>       2           1              NY           MI                  NJ
>        ----
>       3           3              FL           NY                  MA       ----
>       4           1              NH         -----
> ----       ----
> ------------------------------------------------------------------------------------
> For example, for the first respondent, he totally works for 4 firms in
> that year and firm 2 is the one he works the longest time.
> I want to generate a new variable "main_location" to indicate the
> location of the main firm , like this:
> -----------------------------------------------------------
> workerID          main_location
>    1                      NY
>    2                      NY
>    3                      MA
>    4                      NH
> -----------------------------------------------------------
> That is, new variable"main_location" equals variable "location`i' " ,
> where `i' is the value of variable "main_firm". I 'm not sure how to
> code this. Any comments will be helpful.
> Thanks!
>
> Mandy
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index