Hello again,
I am facing this issue in my research project. I need to add some data to my base data set, which will be used as an instrumental variable in my regression. Basically, I have annual bilateral import-export data. My IV data identifies bilateral currency pegging: that is, there are a few countries (in my example below, just the US and Great Britain) which are considered currency "leaders", while the rest of the countries are potentially currency "followers"; they peg their currency to the leader's. If there is a follower-leader relationship, the "peg" variable = 1, else = 0.
In my main data set though, since trade flows both ways, there are two entries per country pair (i.e. USA -> ARG, then ARG -> USA). I am trying to create the "leader" variable, which will equal the value of the leader country, only if the pair contains a potential leader country (USA or GBR), then the "follower" variable will just be equal to the other country in the pair. I have tried using inlist and cond to generate this variable, but I don't think they allow for these types of conditions. See the sample data below:
In my IV data, in the year 2000, Argentina pegged their currency to the US dollar. In order to merge the data though, I believe I need these "follower" and "leader" variables in my master data. I am also not restricting myself to only use this method; I am open to changing my IV data format if creating this variable in my master data is impossible. Below is a very crude attempt I made at making these variables, which of course, does not work.
I am facing this issue in my research project. I need to add some data to my base data set, which will be used as an instrumental variable in my regression. Basically, I have annual bilateral import-export data. My IV data identifies bilateral currency pegging: that is, there are a few countries (in my example below, just the US and Great Britain) which are considered currency "leaders", while the rest of the countries are potentially currency "followers"; they peg their currency to the leader's. If there is a follower-leader relationship, the "peg" variable = 1, else = 0.
In my main data set though, since trade flows both ways, there are two entries per country pair (i.e. USA -> ARG, then ARG -> USA). I am trying to create the "leader" variable, which will equal the value of the leader country, only if the pair contains a potential leader country (USA or GBR), then the "follower" variable will just be equal to the other country in the pair. I have tried using inlist and cond to generate this variable, but I don't think they allow for these types of conditions. See the sample data below:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year str3(country_exp country_imp) str7 countries str1(leader follower) 2000 "USA" "ARG" "USA_ARG" "." "." 2000 "ARG" "USA" "ARG_USA" "." "." 2000 "GBR" "CHN" "GBR_CHN" "." "." 2000 "CHN" "GBR" "CHN_GBR" "." "." end
Code:
gen leader = cond(country_exp == "USA" | "GBR" | country_imp == "USA" | "GBR", `country_exp' | `country_imp')
Comment