This is my first post, so I apologize in advance if anything needs clarification.
I am working on trade flows and have some data for the ReporterCountry, PartnerCountry, T_Product (type of product traded) and year. Here is a working example of my dataset:
Code:
input str3 Rep_country str4 Part_country str2 T_product str4 year USA CAN X1 2000 FRA AUS X2 2003 RUS EU15 X1 2001 JPN BRA X3 2000 ARG EU15 X2 2004 end
I have coded some lines but I do not know if my approach is even correct because it reports an error. So any help would be very welcome. Thanks!
Code:
egen id = group(Rep_country Part_country T_product) sort id local EU15 AUT BEL DEU DNK ESP FIN FRA GBR GRC IRL ITA LUX NLD PRT SWE local N : word count `EU15' expand `N' if Part_country == "EU15" bys id (year) : gen tag = _n gen newpartner = . local EU15 AUT BEL DEU DNK ESP FIN FRA GBR GRC IRL ITA LUX NLD PRT SWE local N : word count `EU15' forval i = 1/`N'{ di `i' local new : word `i' of `EU15' di "`new'" replace newpartner = "`new'" if tag == `i' }
Code:
1 AUT type mismatch r(109); end of do-file r(109);
0 Response to Expand data and replacing multiple observations using elements of a local variable
Post a Comment