-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataConstruction.log
290 lines (236 loc) · 7.88 KB
/
dataConstruction.log
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
-------------------------------------------------------------------------------
name: <unnamed>
log: /Users/stevenchun/Google Drive/School/ECON45/Culminating/dataConst
> ruction.log
log type: text
opened on: 16 May 2018, 14:15:50
.
.
. // Generate dummy for old variables
. clear
. import delimited using "./Dream-4-17-16.csv"
(11 vars, 30,000 obs)
.
. duplicates drop vendor_name, force
Duplicates in terms of vendor_name
(29,032 observations deleted)
.
. drop hash market_name item_link price name description image_link add_time sh
> ip_from v11
.
. gen inMarket2016 = 1
.
. save dream2016, replace
file dream2016.dta saved
.
. // Work on 2017 cocaine prices
. clear
.
. local shipVars ships_to_us ships_from_us ships_to_nl ///
> ships_from_nl ships_to_fr ships_from_fr ships_to_gb ///
> ships_from_gb ships_to_ca ships_from_ca ships_to_de ///
> ships_from_de ships_to_au ships_from_au ships_to_eu ///
> ships_from_eu ships_to_es ships_from_es ships_to_namerica ///
> ships_from_namerica ships_to_be ships_from_be ships_to_ww ///
> ships_from_ww ships_to_si ships_from_si ships_to_it ships_from_it ///
> ships_to_dk ships_from_dk ships_to_samerica ships_from_samerica ///
> ships_to_ch ships_from_ch ships_to_br ships_from_br ships_to_cz ///
> ships_from_cz ships_to_se ships_from_se ships_to_co ships_from_co ///
> ships_to_cn ships_from_cn ships_to_pl ships_from_pl ships_to_gr ///
> ships_from_gr
.
. local encodedShipVars shipsToUS shipsFromUS shipsToNL ///
> shipsFromNL shipsToFR shipsFromFR shipsToGB ///
> shipsFromGB shipsToCA shipsFromCA shipsToDE ///
> shipsFromDE shipsToAU shipsFromAU shipsToEU ///
> shipsFromEU shipsToES shipsFromES shipsToNAMERICA ///
> shipsFromNAMERICA shipsToBE shipsFromBE shipsToWW ///
> shipsFromWW shipsToSI shipsFromSI shipsToIT shipsFromIT ///
> shipsToDK shipsFromDK shipsToSAMERICA shipsFromSAMERICA ///
> shipsToCH shipsFromCH shipsToBR shipsFromBR shipsToCZ ///
> shipsFromCZ shipsToSE shipsFromSE shipsToCO shipsFromCO ///
> shipsToCN shipsFromCN shipsToPL shipsFromPL shipsToGR ///
> shipsFromGR
.
. local n : word count `shipVars'
.
. import delimited using "./data/dream_market_cocaine_listings.csv"
(64 vars, 1,504 obs)
.
. forvalues i = 1/`n' {
2. local a : word `i' of `shipVars'
3. local b : word `i' of `encodedShipVars'
4. di "`a' `b'"
5. gen `b' = (`a' == "TRUE")
6. //encode `a', generate(`b')
. drop `a'
7. }
ships_to_us shipsToUS
ships_from_us shipsFromUS
ships_to_nl shipsToNL
ships_from_nl shipsFromNL
ships_to_fr shipsToFR
ships_from_fr shipsFromFR
ships_to_gb shipsToGB
ships_from_gb shipsFromGB
ships_to_ca shipsToCA
ships_from_ca shipsFromCA
ships_to_de shipsToDE
ships_from_de shipsFromDE
ships_to_au shipsToAU
ships_from_au shipsFromAU
ships_to_eu shipsToEU
ships_from_eu shipsFromEU
ships_to_es shipsToES
ships_from_es shipsFromES
ships_to_namerica shipsToNAMERICA
ships_from_namerica shipsFromNAMERICA
ships_to_be shipsToBE
ships_from_be shipsFromBE
ships_to_ww shipsToWW
ships_from_ww shipsFromWW
ships_to_si shipsToSI
ships_from_si shipsFromSI
ships_to_it shipsToIT
ships_from_it shipsFromIT
ships_to_dk shipsToDK
ships_from_dk shipsFromDK
ships_to_samerica shipsToSAMERICA
ships_from_samerica shipsFromSAMERICA
ships_to_ch shipsToCH
ships_from_ch shipsFromCH
ships_to_br shipsToBR
ships_from_br shipsFromBR
ships_to_cz shipsToCZ
ships_from_cz shipsFromCZ
ships_to_se shipsToSE
ships_from_se shipsFromSE
ships_to_co shipsToCO
ships_from_co shipsFromCO
ships_to_cn shipsToCN
ships_from_cn shipsFromCN
ships_to_pl shipsToPL
ships_from_pl shipsFromPL
ships_to_gr shipsToGR
ships_from_gr shipsFromGR
.
. //Fix prices!!
. //
> 1.5 then 1,5 then .5 then ,5 then 5
. gen stringGrams = regexs(0) if(regexm(product_title, "[0-9]\.[0-9]+[ ]?[Gg]|[
> 0-9]\,[0-9]+[ ]?[Gg]|\.[0-9]+[ ]?[Gg]|\,[0-9]+[ ]?[Gg]|\.?[0-9]+[ ]?[Gg]"))
(29 missing values generated)
.
. gen stringKilos = regexs(0) if(regexm(product_title, "[0-9]\.[0-9]+[ ]?[Kk]|[
> 0-9]\,[0-9]+[ ]?[Kk]|\.[0-9]+[ ]?[Kk]|\,[0-9]+[ ]?[Kk]|\.?[0-9]+[ ]?[Kk]"))
(1,473 missing values generated)
.
. // destring periods and commas
. destring stringGrams, ignore(" " "g" "G") generate(numGrams) force
stringGrams: contains nonnumeric characters not specified in ignore()
stringGrams: characters space g G removed; numGrams generated as double
(74 missing values generated)
.
. destring stringGrams, ignore(" " "g" "G") dpcomma generate(numCommaGrams) for
> ce
stringGrams: contains nonnumeric characters not specified in ignore()
stringGrams: characters space g G removed; numCommaGrams generated as double
(291 missing values generated)
.
. // destring kils
.
. destring stringKilos, ignore(" " "k" "K") generate(numKilos)
stringKilos: characters space k K removed; numKilos generated as byte
(1473 missing values generated)
.
. // set fixed Grams to the appropriate amoun
. gen fixedGrams = numCommaGrams
(291 missing values generated)
. replace fixedGrams = numGrams if (missing(fixedGrams))
(262 real changes made)
. replace fixedGrams = numKilos * 1000 if (missing(fixedGrams))
(29 real changes made)
.
. // recalculate btc prices
. replace grams = fixedGrams
(52 real changes made)
. replace cost_per_gram = btc_price / fixedGrams
(319 real changes made)
. replace cost_per_gram_pure = btc_price / (fixedGrams *(quality / 100))
(381 real changes made)
.
. // From Coindex, average for the week the scraper was running.
. local btcInDollars = 2284.165
.
. // Convert to US dollars
. gen usPrice = btc_price * `btcInDollars'
. gen usPricePerGram = cost_per_gram * `btcInDollars'
. gen usPricePerGramPure = cost_per_gram_pure * `btcInDollars'
.
. // Generate flake dummy
. gen flake = regexm(lower(product_title), "fish|scale|flake")
.
. // Shipping dummies
.
.
. // Generate logs
. gen lnUSPricetPerGram = ln(usPricePerGram)
. gen lnUSPricePerGramPure = ln(usPricePerGramPure)
. gen lnSuccessfulTrans = ln(successful_transactions)
. gen lnRating = ln(rating)
.
. // Generate interactions
. //gen escrowlnSuccessfulTrans = lnSuccessfulTrans * escrow
. egen medianTransactions = median(successful_transactions)
. gen youngVendor = successful_transactions < medianTransactions
. gen escrowYoung = escrow*youngVendor
. gen ratingYoung = rating*youngVendor
.
.
.
. table escrow, content(mean rating sd rating mean cost_per_gram sd cost_per_gr
> am mean cost_per_gram_pure)
----------------------------------------------------------------------------
escrow | mean(rating) sd(rating) mean(cost~m) sd(cost_p~m) mean(cost~e)
----------+-----------------------------------------------------------------
0 | 4.892276 .0962092 .0369528 .0254982 .0418672
1 | 4.881744 .1282268 .0313348 .0215021 .035568
----------------------------------------------------------------------------
. // sum rating age payoff in_market
.
. //drop unneeded variables
. drop fixedGrams
. drop numKilos
. drop numCommaGrams
. drop numGrams
. drop stringGrams
. drop stringKilos
. drop medianTransactions
.
. // Merge the datasets
.
. merge m:1 vendor_name using dream2016.dta
Result # of obs.
-----------------------------------------
not matched 2,183
from master 1,247 (_merge==1)
from using 936 (_merge==2)
matched 257 (_merge==3)
-----------------------------------------
. drop if _merge == 2
(936 observations deleted)
.
. replace inMarket2016 = 0 if (inMarket2016 == .)
(1,247 real changes made)
.
. save cocainePrices, replace
file cocainePrices.dta saved
.
.
.
.
.
.
.
.
. capture log close