Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: code for merging data
From
John Luke Gallup <[email protected]>
To
[email protected]
Subject
Re: st: code for merging data
Date
Mon, 21 Jan 2013 10:00:42 -0800
Prakash,
The problem is that you are reloading the original data in lev3_1.dta each time you run the loop.
Try the following:
clear
set mem 700m
set more off
use lev3_1.dta
foreach l of numlist 4/9 {
merge commonid using lev`l'_1.dta
ren _merge merge3_`l'
}
save merged_data, replace
John
On Jan 20, 2013, at 11:12 PM, Prakash Singh <[email protected]> wrote:
> Dear stata listers
> I need help in correcting my programming code to merge data set. I am
> using stata 10.
>
> I have 7 stata data files which I need to merge. I wrote code for this
> but it is only merging last data file to the first one. Please suggest
> me something on this, my code is
>
> clear
> set mem 700m
> set more off
> tempfile mydata
> foreach l of numlist 4/9 {
> use lev3_1.dta
> merge commonid using lev`l'_1.dta
> capture merge using `mydata'
> ren _merge merge3_`l'
> save `mydata', replace
> }
>
> Please suggest me that where is the mistake happening in this code.
>
>
> Regards
> Prakash
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/