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   "Martin Weiss" <[email protected]>
To   <[email protected]>
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" <[email protected]>
To: <[email protected]>
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
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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index