Hello,
I am trying to merge one file in a folder with every other file in it by looping through every file in the folder. Below is my code:
Code:
local files : dir "E:\WeatherData" files "*.dta"
cd "E:\WeatherData"
foreach file in `files' {
use file, clear
merge 1:1 gridNumber using Gridnumbers
}
As you can see, Gridnumbers is the file I want to merge everything with and gridNumber is the variable I want to merge on. The Gridnumbers file contains two columns: "gridNumber", which lists every grid number in my data set (my data geographically segments the U.S. into a grid) and "countyCode", which assigns each grid number to a county code corresponding to the county in which that grid number is located (counties are larger geographical units than grid areas - one county might correspond to several grid numbers).The other files in the folder contain daily temperature observations at the grid level that I want to merge with the Gridnumbers file so that every observation is tied to the county in which the observation was taken.
The first two command lines work fine but when I run the foreach loop Stata returns the following:
file file.dta not found
r(601);
Am I making a simple mistake or should I try something entirely different?
Thanks in advance.
0 Response to Merging one file with every other file in folder
Post a Comment