Dear Stata List Members,
I wanted to combine variables of two dataset in one big dataset. Upon researching, I think we have to use the merge command. I have implemented it with sample data in help files but I am having difficulties merge two panel datasets both in long format in my context.
I get the error "variables CountryCode Year do not uniquely identify observations in the using data". I have read the help documentation of Stata on merge and I think I just need a 1:1 merge with CountryCode and Year being the common identifiers. I also have a hunch that the problem is because the countries are repeated and that is causing the problem. However, I am unable over come the problem to obtain what I want.
My "using" dataset sample is as follows:
Sample "Master" Dataset sample is as follows:
I have tried the following code but get the error ""variables CountryCode Year do not uniquely identify observations in the using data":
So, how might I merge the variables of two datasets in one dataset according to country year in this case? Thank you in advance for you help.
Cheers,
Roger
I wanted to combine variables of two dataset in one big dataset. Upon researching, I think we have to use the merge command. I have implemented it with sample data in help files but I am having difficulties merge two panel datasets both in long format in my context.
I get the error "variables CountryCode Year do not uniquely identify observations in the using data". I have read the help documentation of Stata on merge and I think I just need a 1:1 merge with CountryCode and Year being the common identifiers. I also have a hunch that the problem is because the countries are repeated and that is causing the problem. However, I am unable over come the problem to obtain what I want.
My "using" dataset sample is as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str52 CountryName str3 CountryCode int Year double(AG_AGR_TRAC_NO_wb AG_CON_FERT_PT_ZS_wb) "Ecuador" "ECU" 1969 2900 . "Ecuador" "ECU" 1970 3100 . "Ecuador" "ECU" 1971 3400 . "Ecuador" "ECU" 1972 3700 . "Ecuador" "ECU" 1973 4200 . "Ecuador" "ECU" 1974 4945 . end
Sample "Master" Dataset sample is as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 CountryCode str34 CountryName str29 currency_unit int Year float(rgdpe_pwt rgdpo_pwt) double pop_pwt "ECU" "Ecuador" "US Dollar" 1964 14246.126 14603.285 5.079177674303292 "ECU" "Ecuador" "US Dollar" 1965 14654.083 15095.12 5.23261926779025 "ECU" "Ecuador" "US Dollar" 1966 15186.637 15549.03 5.390954271694549 "ECU" "Ecuador" "US Dollar" 1967 16306.564 16674.877 5.554325046865233 "ECU" "Ecuador" "US Dollar" 1968 17071.074 17443.906 5.722517076954425 "ECU" "Ecuador" "US Dollar" 1969 17508.463 17877.787 5.895319745911485 "ECU" "Ecuador" "US Dollar" 1970 18884.623 19135.959 6.07252 "ECU" "Ecuador" "US Dollar" 1971 19630.855 20283.936 6.248831 "ECU" "Ecuador" "US Dollar" 1972 20757.283 22304.63 6.428706999999999 end
Code:
use ".\pwt90.dta", clear merge m:1 CountryCode Year using ".\FullWorldBankinStata.dta" and merge 1:1 CountryCode Year using ".\FullWorldBankinStata.dta"
Cheers,
Roger
Comment