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

 From "Martin Weiss" To Subject Re: st:how to connect a variable's value with another variable's name Date Wed, 25 Mar 2009 21:52:43 +0100

<>

Brute force:

****
g main_location=cond( main_firm==1, location1, cond( main_firm==2, location2, cond( main_firm==3, location3, cond( main_firm==4,location4,""))))
****

HTH
Martin
_______________________
----- Original Message ----- From: "Mandy fu" <mandy.fu1@gmail.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Wednesday, March 25, 2009 9:04 PM
Subject: st:how to connect a variable's value with another variable's name

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