Hello Everyone,
I want to merge three files using macros and foreach loop. The file names are 1.dta, 2.dta, and 3.dta. Each file has two variables. 1.dta has id and age. 2.dta has id and edu. 3.dta has id and state. Taking id as a common variable I want to merge these three and want to generate a new dta with id, age, edu and state. The code I followed is the following one:
cd "F:\UDOY\Graduation\ECON 7th Semester_UDOY\Research Methodology\RM Class Lectures\NH Stata\Merging multiple files"
use "F:\UDOY\Graduation\ECON 7th Semester_UDOY\Research Methodology\RM Class Lectures\NH Stata\Merging multiple files\1.dta"
local files : dir "F:\UDOY\Graduation\ECON 7th Semester_UDOY\Research Methodology\RM Class Lectures\NH Stata\Merging multiple files" files "*.dta"
foreach file in `files' {
merge id using `file'
}
after running the code it shows "no; data in memory would be lost" in red mark
and if a br the data a variable has been created named as _merge which contain matched(3) in each row.
But I didn't get the expected result.
What should I do now?
Thank You
I want to merge three files using macros and foreach loop. The file names are 1.dta, 2.dta, and 3.dta. Each file has two variables. 1.dta has id and age. 2.dta has id and edu. 3.dta has id and state. Taking id as a common variable I want to merge these three and want to generate a new dta with id, age, edu and state. The code I followed is the following one:
cd "F:\UDOY\Graduation\ECON 7th Semester_UDOY\Research Methodology\RM Class Lectures\NH Stata\Merging multiple files"
use "F:\UDOY\Graduation\ECON 7th Semester_UDOY\Research Methodology\RM Class Lectures\NH Stata\Merging multiple files\1.dta"
local files : dir "F:\UDOY\Graduation\ECON 7th Semester_UDOY\Research Methodology\RM Class Lectures\NH Stata\Merging multiple files" files "*.dta"
foreach file in `files' {
merge id using `file'
}
after running the code it shows "no; data in memory would be lost" in red mark
and if a br the data a variable has been created named as _merge which contain matched(3) in each row.
But I didn't get the expected result.
What should I do now?
Thank You
Comment