Hi all,
I am working on a cross-country dataset. The dataset is created when I merge the bilateral trade data with the country characteristics (such as GDP and bilateral trade agreements). When I merge I use the exporter ISO code, the importer ISO code and time as the identifiers. My master data is the trade data and my using data is the characteristics data. In the using data I rename the country of origin the exporter and the country of destination the importer. For instance, in the merged data I will have the trade value exported by country A to country B, the GDP of country A and of country B and whether A and B have a trade agreement. However, what the data misses is when B exports to A I don't have the characteristics because the using data already considers A as the origin and B as the destination (due to the way I rename the variables in the using data). I cannot merge the data one more time with A being the destination and B as the origin because of duplication (the free trade agreement variable will appear twice). I was then thinking of replacing the missing observation when B exports to A by the value of the observation when A exports to B thanks to symmetry. I checked on the forum and what I can find is I need know the ID of the observation (i.e. replace GDP = GDP[6]). In my case, I only know the observation satisfies certain conditions: replace GDP = GDP of the observation whose Exporter=Importer and Importer=Exporter.
To illustrate my point, here is an example:
Before:
Exporter Importer Exporter_GDP Importer_GDP Trade value
A B 100 200 50
B A . . 70
After
Exporter Importer Exporter_GDP Importer_GDP Trade value
A B 100 200 50
B A 200 100 70
Could you please give me some suggestions?
Many thanks,
Gia Cat Luong
Related Posts with Replacing missing variable with other observations that satisfy certain conditions
Store r-class values and tabulate laterHello all, I am new to stata and my work is about medical data. My data are about diagnostic perfor…
Expand rolling sequencies of observation within ID ifHi, I am using a panel dataset with different countries (example below). For each date there are tw…
Adding a new empty row(year) to an existing datasetHi stata users, I have a dataset from 2008-2018, but want to add a new row 2019. I tried some codes …
Creating a panel dataset using STATAHello colleagues I am analysing the impact of COVID 19 on firms. I want to use two waves of the Wor…
Merge 7 datasetsHello. I have seven different datasets (one per year from 2007 to 2013) with all the variable being…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing variable with other observations that satisfy certain conditions
Post a Comment