I am trying to merge two data and appending it to the previous merged data.
Below are my Stata codes
================================================== =========
clear all
set more off, permanently
use "U:\state\ARUNACHAL PRADESH.dta" (A state file with lots of districts)
levelsof distname, local(dis) (Trying to extract the district names)
>"CHANGLANG"' `"DIBANG VALLEY"' `"EAST KAMENG"' `"EAST SIANG"' `"KURUNG KUMEY"' `"LOHIT"' `"LOWER DIBANG VALLEY"' `
> "LOWER SUBANSIRI"' `"PAPUM PARE"' `"TAWANG"' `"TIRAP"' `"UPPER SIANG"' `"UPPER SUBANSIRI"' `"WEST KAMENG"' `"WEST
> SIANG"'
foreach s of local dis {
use "U:\Excel file\Arunachal Pradesh _`s'.dta"
merge 1:1 distname blkname using "U:\state\ARUNACHAL PRADESH.dta"
tostring BlockDifference, replace
append using "U:\merge\Arunachal Pradesh.dta"
save "U:\merge\Arunachal Pradesh.dta", replace
}
>(note: variable distname was str9, now str25 to accommodate using data's values)
>(note: variable blkname was str14, now str35 to accommodate using data's values)
>variables distname blkname do not uniquely identify observations in the using data
r(459);
================================================== ========
Then the error message pops out and when I browse the data,
there is only the first district (CHANGLANG)'s data.
What could have I done wrong?
Below are my Stata codes
================================================== =========
clear all
set more off, permanently
use "U:\state\ARUNACHAL PRADESH.dta" (A state file with lots of districts)
levelsof distname, local(dis) (Trying to extract the district names)
>"CHANGLANG"' `"DIBANG VALLEY"' `"EAST KAMENG"' `"EAST SIANG"' `"KURUNG KUMEY"' `"LOHIT"' `"LOWER DIBANG VALLEY"' `
> "LOWER SUBANSIRI"' `"PAPUM PARE"' `"TAWANG"' `"TIRAP"' `"UPPER SIANG"' `"UPPER SUBANSIRI"' `"WEST KAMENG"' `"WEST
> SIANG"'
foreach s of local dis {
use "U:\Excel file\Arunachal Pradesh _`s'.dta"
merge 1:1 distname blkname using "U:\state\ARUNACHAL PRADESH.dta"
tostring BlockDifference, replace
append using "U:\merge\Arunachal Pradesh.dta"
save "U:\merge\Arunachal Pradesh.dta", replace
}
>(note: variable distname was str9, now str25 to accommodate using data's values)
>(note: variable blkname was str14, now str35 to accommodate using data's values)
>variables distname blkname do not uniquely identify observations in the using data
r(459);
================================================== ========
Then the error message pops out and when I browse the data,
there is only the first district (CHANGLANG)'s data.
What could have I done wrong?
Comment