-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data_clearing.do
160 lines (95 loc) · 3.71 KB
/
Data_clearing.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
******************************************
*********** Data Clearing Code ***********
******************************************
*********** Income Segregation ***********
cd "C:\Users\A\OneDrive\바탕 화면\Data Analysis Program\2024_Causal_Inference\Trading_Income_Segregation\Data_Clearing_Incomeseg"
use segr_cz_1990, clear
append using segr_cz_2000
append using segr_cz_2012
save total_segr_index, replace
******** CBP into Commuting Zone *********
cd "C:\Users\A\OneDrive\바탕 화면\Data Analysis Program\2024_Causal_Inference\Trading_Income_Segregation\Data_Clearing_Share_Making"
import delimited "efsy_panel_native.csv", clear
keep if year == 1980 | year == 1990 | year == 2000 | year == 2012
gen ctycode = fipstate*1000 + fipscty
keep year emp ctycode naics sic
tostring naics, replace
merge n:n naics using SIC_NAICS_concordance
gen sic_mat = sic
replace sic_mat = SIC_code if sic == ""
keep year ctycode sic_mat emp
drop if ctycode==.
save sharedata_1980_2012, replace
//// 1980 segregate
keep if year == 1980
rename (emp year) (emp_1980 year_1980)
save sharedata_1980, replace
//// segregate others
use sharedata_1980_2012, clear
keep if year ~= 1980
save sharedata_1990_2012, replace
//// merge two of those
merge m:m ctycode sic_mat using sharedata_1980
drop year_1980
replace emp_1980 = 0 if emp_1980==.
replace emp = 0 if emp==.
drop if year == .
drop if sic_mat==""
drop emp
save panel_data_fin_1990_2012, replace
*** county to commuting zone
rename ctycode cty_fips
merge m:m cty_fips using cw_cty_czone
drop if czone == .
drop if emp_1980 == .
egen emp_czone = total(emp), by (czone sic_mat year)
egen emp_czone_1980 = total(emp_1980), by (czone sic_mat year)
duplicates drop czone year sic_mat, force
keep year emp sic_mat czone emp_czone emp_czone_1980
save data_cbp_cz, replace
*********** Import penetration and IV ***********
cd "C:\Users\A\OneDrive\바탕 화면\Data Analysis Program\2024_Causal_Inference\Trading_Income_Segregation\Data_Clearing_Industry_Making"
*** china_us_data 2012
import delimited "China_US_Trade_Data.csv", clear
keep refyear period reporteriso flowcode partneriso cmdcode primaryvalue
keep if flowcode == "M"
rename (cmdcode period) (commodity year)
tostring commodity, replace
keep if year == 2012
merge m:m commodity year using hs_sic_imports
keep year reporteriso flowcode partneriso commodity primaryvalue sic
drop if sic == "" | sic == "."
drop if primaryvalue==.
egen import_value = total(primaryvalue), by (year sic)
rename sic sic_mat
drop commodity flowcode
rename (reporteriso partneriso) (importer exporter)
duplicates drop year sic_mat, force
drop primaryvalue
save china_us_trade_2012, replace
*** china_other_data
import delimited "China_Other_Trade_Data.csv", clear
keep if flowcode == "X"
keep refyear period reporteriso flowcode partneriso cmdcode primaryvalue
rename (cmdcode period) (commodity year)
tostring commodity, replace
keep if year == 2012
merge m:m commodity year using hs_sic_imports
keep year reporteriso flowcode partneriso commodity primaryvalue sic
drop if sic == "" | sic == "."
drop if primaryvalue==.
egen export_value = total(primaryvalue), by (year sic)
rename sic sic_mat
drop commodity flowcode
rename (reporteriso partneriso) (exporter importer)
duplicates drop year sic_mat, force
drop primaryvalue
replace importer = "OTH"
rename export_value values
save china_other_trade_2012, replace
**** trade data merge
use sic_trade_data_1990_2000, clear
tostring sic_mat, replace
append using china_other_trade_2012
append using china_us_trade_2012
save trade_data_1990_2012, replace