Hi,
I am a beginner in Stata (using Stata 16) and after going through many of the posts regarding merging multiple files from a folder, I tried to write the following code but I received an error. I will describe the data, folder structure, code and error messages below:
Data: I have quarterly bank data from FDIC where each csv file corresponds to one quarter and within each file, different banks are identified using a variable called 'cert'. For every file, there is also a column named 'repdte' which lists the quarter for the particular file (so for eg, I will have a file named All_Reports_20170930_U.S. Government Obligations.csv which will have many columns giving data regarding US Govt Obligations and there will also be two additional columns cert and repdte listing the bank ID and 20170930 respectively for the entire file).
Sample csv files may be downloaded from: https://www7.fdic.gov/sdi/download_l...st_outside.asp For my testing, I am using the 2018, 2017 files for quarters 1231 and 0930 for the files "Unused Commitments Securitization" and "U.S. Government Obligations".
What I want to do: I want to merge all the bank data across banks and quarter (panel data) and to do this, i figured I should use the command: merge 1:1 cert repdte using filename
Code:
clear all
pwd
cd "C:\Users\HP\Dropbox\Data\Test2"
tempfile mbuild
clear
save `mbuild', emptyok
foreach year in 2018 2017{
foreach dm in 1231 0930 {
foreach name in "Unused Commitments Securitization" "U.S. Government Obligations"{
import delimited "C:\Users\HP\Dropbox\Data\Test2\All_Reports_`y ear' `dm'_`name'", clear
gen source = "C:\Users\HP\Dropbox\Data\Test2\All_Reports_`y ear' `dm'_`name'"
merge 1:1 cert repdte using `mbuild'
save `mbuild', replace
}
}
}
Error:
.
. foreach year in 2018 2017{
2. foreach dm in 1231 0930 {
3. foreach name in "Unused Commitments Securitization" "U.S. Governmen
> t Obligations"{
4. import delimited "C:\Users\HP\Dropbox\Data\Test2\All_Report
> s_`year'`dm'_`name'", clear
5. gen source = "C:\Users\HP\Dropbox\Data\Test2\All_Reports_`y
> ear'`dm'_`name'"
6. merge 1:1 cert repdte using `mbuild'
7. save `mbuild', replace
8.
. }
9. }
10. }
(52 vars, 5,415 obs)
no variables defined
r(111);
Could someone please help me understand what i am doing wrong and how I can achieve what I am trying to do? Additionally, I also want to be able to retrieve the merged file to do further analysis on Stata and also export it to a folder on my computer - how should I do that?
Related Posts with Problem with merging multiple csv files using merge 1:1
Stata output InterpretationKindly assist with the interpretation of Table 2, Figure 1, Table 3 and Table 4 in the attached docu…
How to calculate odds ratio for C.DVHi everyone, How to calculate odds ratio from continuous DV (0 - 100) then transformation log …
Stata output InterpretationKindly assist with the discussion and interpretation of Tables 2-4 and Figure 1 in the attached docu…
Difference -in-difference research designHi all, I have a panel data (firm and year). I create Post indicator for states that adopt certain …
Keeping variables with different cases in each groupDear Statalist users, I would like to ask this data management questions. For example I have indivi…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with merging multiple csv files using merge 1:1
Post a Comment