Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to quickly merge by the range of a third variable?


From   Sean <[email protected]>
To   [email protected]
Subject   Re: st: How to quickly merge by the range of a third variable?
Date   Mon, 10 Oct 2005 09:12:11 -0500

Thanks Taavi; before your hint I didn't even think of merging by two
identifying variables.

On 10/10/05, Taavi Lai <[email protected]> wrote:
> Maybe there is a better way to do it but I would generate one dataset
> containing all the B-s and correstponding year by -append- and did the
> -merge- using this composite file by variables id and year. sth like
>
> use b1, clear
> gen year==1900
> save b_comp, replace
> use b2, clear
> gen year==1901
> append using b_comp
> save b_comp, replace
> use a, clear
> merge year id using b_comp
>
> And you could use looping for the first part but as I'm not proficent
> with it so I'd better leave it for other list members
>
> Best regards
> Taavi
>
> Sean wrote:
>
> >Dear Statalisters,
> >
> >I have a quick question about  how to speed up the merging process.
> >Suppose I have one A dataset and several B dataset, denoted as B1, B2, B3, etc.
> >
> >In A dataset, I have individuals' id numbers along with his/her birth
> >city and birth year. Now in B's datasets, it stores the information of
> >all the cities in a particular year, such as B1: all the cities for
> >year 1, B2: all the cities for year2, B3 for year3, etc. For example,
> >in year 1, I can get every city's population size for that year.
> >
> >Now my goal is to get each individual's birth city population size, of
> >course, for that particular year when the individual was born. To
> >summarize, in dataset A, I have the following variables:
> >
> >id  birthyear birthcity
> >
> >in B's datasets, I have
> >
> >cityid population
> >
> >I am aware that I should merge the right B dataset with A through
> >city, however, which year when the individual was born determines
> >which B dataset I should merge for that observation. I didn't find by:
> >or if... conditional command for "merge", as I imagined.
> >
> >Is there a quickest way to finish this mission?
> >
> >Thanks all.
> >
> >*
> >*   For searches and help try:
> >*   http://www.stata.com/support/faqs/res/findit.html
> >*   http://www.stata.com/support/statalist/faq
> >*   http://www.ats.ucla.edu/stat/stata/
> >
> >
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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