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

From |
Mandy fu <mandy.fu1@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Thu, 26 Mar 2009 00:30:34 -0500 |

Thanks, Mr Weiss and Wade! I appreciate your help. Mandy On 3/25/09, Martin Weiss <martin.weiss1@gmx.de> wrote: > <> > > Tim`s solution is more elegant than mine, and more readily extends to a case > where Mandy faces more than the four locations in her example dataset (which > I suspect is the case). > > > HTH > Martin > _______________________ > ----- Original Message ----- From: "Tim Wade" <wadetj@gmail.com> > To: <statalist@hsphsun2.harvard.edu> > Sent: Thursday, March 26, 2009 2:25 AM > Subject: Re: st:how to connect a variable's value with another variable's > name > > > > 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/ > > > > > > * > * 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/

**References**:**st:how to connect a variable's value with another variable's name***From:*Mandy fu <mandy.fu1@gmail.com>

**Re: st:how to connect a variable's value with another variable's name***From:*Tim Wade <wadetj@gmail.com>

**Re: st:how to connect a variable's value with another variable's name***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: AW: maximum number of characters in do file** - Next by Date:
**R: st: constrained sum of random values** - Previous by thread:
**Re: st:how to connect a variable's value with another variable's name** - Next by thread:
**st: nlogit for analysis of survey results, multiple responses per subject** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |