Hello,
I'm trying to understand a line of code that collapses a dataset I'm working with (I've inherited the do-file that I'm trying to understand). My dataset has US imports data, disaggregated by product (with a corresponding product code called ic), exporter and unit (numbers, pounds, etc). I've given an example below:
product exporter unit free dut ic value quantity miss_q_raw
Cattle UK NUMBER 1 1 0010 21506 556 0
Jute Austria 0 1 3363 54243 . 1
And so on. free is a dummy that is 1 when there is no import tariff (and 0 otherwise); dut is a dummy that is 1 when there is an import tariff (and 0 otherwise); miss_q_raw is a dummy that is 1 when the quantity is missing, and 0 otherwise. The code I'm trying to understand is:
By my understanding, collapse should produce the sum of value and quantity for each combination of exporter-ic-unit, and keep the max value of miss_q_raw, which is 1. But that is not what is produced in the output, which is:
ic exporter value unit product miss_q_raw quantity free dut
0010 Canada 57010 NUMBER Cattle 0 4475 1 0
3351 Austria 1918 Apparel N/A 1 . 0 1
I obviously don't understand what the collapse command is exactly doing here. What is the code doing?
Regards,
Saunok
I'm trying to understand a line of code that collapses a dataset I'm working with (I've inherited the do-file that I'm trying to understand). My dataset has US imports data, disaggregated by product (with a corresponding product code called ic), exporter and unit (numbers, pounds, etc). I've given an example below:
product exporter unit free dut ic value quantity miss_q_raw
Cattle UK NUMBER 1 1 0010 21506 556 0
Jute Austria 0 1 3363 54243 . 1
And so on. free is a dummy that is 1 when there is no import tariff (and 0 otherwise); dut is a dummy that is 1 when there is an import tariff (and 0 otherwise); miss_q_raw is a dummy that is 1 when the quantity is missing, and 0 otherwise. The code I'm trying to understand is:
Code:
collapse (sum) value quantity (first) free dut product (max) miss_q_raw, by(ic exporter unit) order ic exporter value unit product miss_q_raw replace unit = "N/A" if miss_q_raw == 1
ic exporter value unit product miss_q_raw quantity free dut
0010 Canada 57010 NUMBER Cattle 0 4475 1 0
3351 Austria 1918 Apparel N/A 1 . 0 1
I obviously don't understand what the collapse command is exactly doing here. What is the code doing?
Regards,
Saunok
Comment