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 <[email protected]> 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/