--------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone
>  and Hanna (2014) Replication Files - 01102014\Greenstone and Hann
> a (2014) Replication Files (non-zipped folder)\Log/Figure1_0110201
> 4.txt
  log type:  text
 opened on:  12 Feb 2014, 14:19:46

. 
. ******************************************************************
> *****************
. * 1. Generate Figure 1 for Air Data
. ******************************************************************
> *****************
. 
. *** Air ***
. * INDIA: Use AP fixed sample data
. 
. use "${mypath}Data/Air Data/Intermediate Data/e_airpol_city.dta", 
> clear

. 
. * Keep only five year period over which means will be taken, and i
> d info + spm_means
. drop if year > 1995 | year < 1991
(2240 observations deleted)

. keep state district city year e_spm_mean

. 
. * Count number of unique districts w/ pollution data
. * Note: There were 466 districts in all of India as of 1991, as pe
> r 
. *       http://www.censusindia.gov.in/2011census/maps/administrati
> ve_maps/Final%20Atlas%20India%202011.pdf
. bys state district (city year): gen districtcount = 1 if _n == 1
(583 missing values generated)

. count if districtcount == 1
  117

. local districtpct = r(N)/466

. 
. * Collapse to national mean, median, and p99 values over 1991-1995
. rename e_spm_mean tsp_mean

. g tsp_median = tsp_mean
(429 missing values generated)

. g tsp_p99 = tsp_mean
(429 missing values generated)

. g country = "India"

. collapse (mean) tsp_mean (median) tsp_median (p99) tsp_p99, by(cou
> ntry)

. tempfile indiaTSP

. save `indiaTSP'
file C:\Users\sberkou\AppData\Local\Temp\ST_06000001.tmp saved

. 
. * U.S.A.: Use data from Joe Shapiro
. use "${mypath}Data/Air Data/Raw Data/forbook.dta", clear

. 
. * Count number of unique counties w/ pollution data
. * Note: There were 3,141 counties in the US as of 1990, as per htt
> p://www.census.gov/geo/maps-data/data/gazetteer1990.html
. bys statecode countycode (siteid year): gen countycount = 1 if _n 
> == 1
(191187 missing values generated)

. count if countycount == 1
  430

. local countycount = r(N)

. 
. * Change date variable to be a month indicator, and collapse to an
> nual means (the raw form of India's TSP data)
. replace date = substr(date, 5, 2)
(191617 real changes made)

. collapse (mean) samplevalue, by(year statecode countycode siteid)

. 
. * Generate county-wide means (across all sites and all years), to 
> be used to rank counties by pollution
. egen countymean = mean(samplevalue), by(statecode countycode)

. replace countymean = countymean * -1 // multiple by -1 so we can l
> ist in descending order
(3470 real changes made)

. 
. * Rank the counties by their average pollution
. bys countymean statecode countycode (siteid year): gen uniquecount
> y = 1 if _n == 1
(3040 missing values generated)

. sort uniquecounty countymean statecode countycode siteid year

. gen countyrank = _n if uniquecounty == 1
(3040 missing values generated)

. drop countymean uniquecounty

. bys statecode countycode (countyrank): replace countyrank = county
> rank[1] // Assign county rank to all observations from that county
(3040 real changes made)

. 
. * Create a second pollution variable for only those counties above
>  the Xth percentile of pollution
. rename samplevalue samplevalue1

. local countycap = `districtpct' * 3141 // `districtpct' is the % o
> f districts represented in the India dataset. 3141 is the total # 
> of US counties.

. local countycap = round(`countycap') // `countycap' is the number 
> of US counties we want to have in our sample.

. if `countycap' > `countycount' {
.         local countycap = `countycount'
. }

. assert `countycap' <= `countycount' // Ensure that the overall sam
> ple is already over X percent of all US counties

. gen samplevalue2 = samplevalue1 if countyrank <= `countycap'

. 
. * Collapse to national mean, median, and p99 values over 1991-1995
. rename samplevalue1 tsp_mean1

. g tsp_median1 = tsp_mean1

. g tsp_p99_1 = tsp_mean1

. rename samplevalue2 tsp_mean2

. g tsp_median2 = tsp_mean2

. g tsp_p99_2 = tsp_mean2

. g country = "USA"

. 
. collapse (mean) tsp_mean1 tsp_mean2 (median) tsp_median1 tsp_media
> n2 (p99) tsp_p99_1 tsp_p99_2, by(country)

. set obs 2
obs was 1, now 2

. replace tsp_mean1 = tsp_mean2[1] if tsp_mean1 == .
(1 real change made)

. replace tsp_median1 = tsp_median2[1] if tsp_median1 == .
(1 real change made)

. replace tsp_p99_1 = tsp_p99_2[1] if tsp_p99_1 == .
(1 real change made)

. replace country = "USA1" if country == "USA"
country was str3 now str4
(1 real change made)

. replace country = "USA2" if country == ""
(1 real change made)

. rename tsp_mean1 tsp_mean

. rename tsp_median1 tsp_median

. rename tsp_p99_1 tsp_p99

. drop tsp_mean2 tsp_median2 tsp_p99_2

. tempfile usaTSP

. save `usaTSP'
file C:\Users\sberkou\AppData\Local\Temp\ST_06000002.tmp saved

. 
. 
. * CHINA: Use data from Ilya Faibushevich
. use "${mypath}Data/Air Data/Raw Data/amb-tsp.dta", clear

. reshape long _, i(city) j(year)
(note: j = 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 19
> 92 1993 1994 1995)

Data                               wide   ->   long
--------------------------------------------------------------------
> ---------
Number of obs.                       89   ->    1335
Number of variables                  20   ->       7
j variable (15 values)                    ->   year
xij variables:
                  _1981 _1982 ... _1995   ->   _
--------------------------------------------------------------------
> ---------

. rename _ tsp_mean

. drop if year < 1991
(890 observations deleted)

. g tsp_median = tsp_mean
(120 missing values generated)

. g tsp_p99 = tsp_mean
(120 missing values generated)

. g country = "China"

. collapse (mean) tsp_mean (median) tsp_median (p99) tsp_p99, by(cou
> ntry)

. tempfile chinaTSP

. save `chinaTSP'
file C:\Users\sberkou\AppData\Local\Temp\ST_06000003.tmp saved

. 
. * APPEND: Append three countries together
. append using `indiaTSP'

. append using `usaTSP'
tsp_mean was float now double

. 
. g one = 1

. reshape wide tsp_mean tsp_median tsp_p99, i(one) j(country) string
(note: j = China India USA1 USA2)

Data                               long   ->   wide
--------------------------------------------------------------------
> ---------
Number of obs.                        4   ->       1
Number of variables                   5   ->      13
j variable (4 values)           country   ->   (dropped)
xij variables:
                               tsp_mean   ->   tsp_meanChina tsp_mea
> nIndia ... tsp_meanUSA2
                             tsp_median   ->   tsp_medianChina tsp_m
> edianIndia ... tsp_medianUSA2
                                tsp_p99   ->   tsp_p99China tsp_p99I
> ndia ... tsp_p99USA2
--------------------------------------------------------------------
> ---------

. rename tsp_meanChina chinamean

. rename tsp_medianChina chinamedian

. rename tsp_p99China chinap99

. rename tsp_meanIndia indiamean

. rename tsp_medianIndia indiamedian

. rename tsp_p99India indiap99

. rename tsp_meanUSA1 usa1mean

. rename tsp_medianUSA1 usa1median

. rename tsp_p99USA1 usa1p99

. rename tsp_meanUSA usa2mean

. rename tsp_medianUSA usa2median

. rename tsp_p99USA2 usa2p99

. reshape long china india usa1 usa2, i(one) j(stat) string
(note: j = mean median p99)

Data                               wide   ->   long
--------------------------------------------------------------------
> ---------
Number of obs.                        1   ->       3
Number of variables                  13   ->       6
j variable (3 values)                     ->   stat
xij variables:
         chinamean chinamedian chinap99   ->   china
         indiamean indiamedian indiap99   ->   india
            usa1mean usa1median usa1p99   ->   usa1
            usa2mean usa2median usa2p99   ->   usa2
--------------------------------------------------------------------
> ---------

. drop one

. 
. replace china = round(china, 1)
(1 real change made)

. replace india = round(india, 1)
(2 real changes made)

. replace usa1 = round(usa1, 1)
(3 real changes made)

. replace usa2 = round(usa2, 1)
(3 real changes made)

. 
. * Not using median for now, too similar to mean
. drop if stat == "median"
(1 observation deleted)

. 
. generate order = 1 if stat=="mean"
(1 missing value generated)

. replace order = 2 if stat=="median"
(0 real changes made)

. replace order = 3 if stat=="p99"
(1 real change made)

. local cube = char(179)

. * Note that we create two versions -- one where we use the full sa
> mples from India, the US, and China, and one where we limit the US
. *       sample to be the same size (as a proportion of US counties
> ) as the India sample (as a proportion of Indian districts). It tu
> rns out
. *       that they are already the same relative size, so the resul
> ts are identical, and we can just use the first version.
. graph bar usa1 india china, over(stat, sort(order) relabel(1 `"Mea
> n Particulate Matter"' 2 `"99th Percentile Particulate Matter"')) 
> ///
>         ytitle("Particulate Matter" "ug/m`cube'") blabel(bar) barg
> ap(2) ///
>         legend(label(1 "U.S.") label(2 "India") label(3 "China") r
> ows(1)) scheme(s1color) ///
>         bar(1, fcolor(gs5) lcolor(gs5)) bar(2, fcolor(black) lcolo
> r(black)) bar(3, fcolor(white) lcolor(black))

. graph export "${mypath}Output/F1/F1_air1.eps", replace 
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_air1.eps writ
> ten in EPS format)

. graph export "${mypath}Output/F1/F1_air1.png", replace 
(note: file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone 
> and Hanna (2014) Replication Files - 01102014\Greenstone and Hanna
>  (2014) Replication Files (non-zipped folder)\Output/F1/F1_air1.pn
> g not found)
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_air1.png writ
> ten in PNG format)

. /*
> graph bar usa2 india china, over(stat, sort(order) relabel(1 `"Mea
> n Particulate Matter"' 2 `"99th Percentile Particulate Matter"')) 
> ///
>         ytitle("Particulate Matter" "ug/m`cube'") blabel(bar) barg
> ap(2) ///
>         legend(label(1 "Top `countycap' U.S. Counties of `countyco
> unt' available") label(2 "India") label(3 "China") rows(1)) scheme
> (s1color) ///
>         bar(1, fcolor(gs5) lcolor(gs5)) bar(2, fcolor(black) lcolo
> r(black)) bar(3, fcolor(white) lcolor(black))
> graph export "${mypath}Output/F1/F1_air2.eps", replace 
> */
. ******************************************************************
> *****************
. * 2. Generate Figure 1 for Water Data
. ******************************************************************
> *****************
. * Data are means across city-rivers in US and India, from 1998-200
> 2
. insheet using "${mypath}Data/Water Data/Raw Data/water_usindia.csv
> ", clear
(3 vars, 3 obs)

. 
. * Replace with fixed sample numbers
. replace india = 4.17 if stat == "BOD"
(1 real change made)

. replace india = 5.44 if stat == "Fcoli"
(1 real change made)

. replace india = 7.14 if stat == "DO"
(1 real change made)

. replace india = round(india, .01)
(0 real changes made)

. replace us = round(us, .01)
(0 real changes made)

. 
. tempfile temp

. save `temp'
file C:\Users\sberkou\AppData\Local\Temp\ST_06000004.tmp saved

. 
. * China data 6.1.09
. * Data from Avi Ebenstein at http://people.rwj.harvard.edu/~aebens
> te/data.html#water_pollution.
. 
. use "${mypath}Data/Water Data/Raw Data/waterpoints_data.dta", clea
> r

. 
. g ones = 1

. collapse (sum) ones, by(rsystem)

. keep if rsystem == "Songhua R" | rsystem == "Liao R" | rsystem == 
> "Yellow R" | rsystem == "Yangtze R" | rsystem == "Pearl R" | rsyst
> em == "Huai R"
(5 observations deleted)

. 
. g bod = 0

. replace bod = 2.78 if rsystem == "Songhua R"
(1 real change made)

. replace bod = 6.25 if rsystem == "Liao R"
(1 real change made)

. replace bod = 2.75 if rsystem == "Yellow R"
(1 real change made)

. replace bod = 1.50 if rsystem == "Yangtze R"
(1 real change made)

. replace bod = 2.70 if rsystem == "Pearl R"
(1 real change made)

. replace bod = 6.05 if rsystem == "Huai R"
(1 real change made)

. 
. g do = 0

. replace do = 7.98 if rsystem == "Songhua R"
(1 real change made)

. replace do = 6.75 if rsystem == "Liao R"
(1 real change made)

. replace do = 7.75 if rsystem == "Yellow R"
(1 real change made)

. replace do = 7.95 if rsystem == "Yangtze R"
(1 real change made)

. replace do = 4.65 if rsystem == "Pearl R"
(1 real change made)

. replace do = 5.90 if rsystem == "Huai R"
(1 real change made)

. 
. g bod_weight = bod * ones

. g do_weight = do * ones

. 
. collapse (sum) bod_weight do_weight ones

. g bod = bod_weight / ones /* BOD = 3.48 */

. g do = do_weight / ones /* DO = 6.99 */

. 
. use `temp', clear

. g china = 3.48 if stat == "BOD"
(2 missing values generated)

. replace china = 6.99 if stat == "DO"
(1 real change made)

. outsheet using "${mypath}Output/F1/F1_water.txt", replace

. 
. * Graph BOD/Fcoli and DO separately because they have different di
> rections (higher DO is actually better water quality)
. graph bar us india china if stat != "DO", over(stat, relabel(1 `" 
> "Biochemical Oxygen" "Demand" "' 2 `" "Logarithm of" "Fecal Colifo
> rms" "') gap(*2)) ///
>         legend(cols(1) label(1 "United States") label(2 "India") l
> abel(3 "China")) scheme(s1color) blabel(bar) yscale(range(0 6)) yl
> ab(0 1 2 3 4 5 6) ///
>         outergap(*4) bargap(5) ytitle("Mean Value", margin(small))
>  bar(1, fcolor(gs5) lcolor(gs5)) bar(2,fcolor(black) lcolor(black)
> ) bar(3, fcolor(white) lcolor(black)) ///
>         saving("${mypath}Output/F1/F1_bodfcoli.gph", replace)
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_bodfcoli.gph 
> saved)

. 
. graph bar us india china if stat == "DO", over(stat, relabel(1 "Di
> ssolved Oxygen")) bargap(5) legend(cols(1) label(1 "United States"
> ) label(2 "India") label(3 "China")) ///
>         ytitle("Mean Value", margin(small)) outergap(*13) bar(1, f
> color(gs5) lcolor(gs5)) blabel(bar) ///
>         scheme(s1color) bar(2,fcolor(black) lcolor(black)) bar(3, 
> fcolor(white) lcolor(black)) yscale(range(0 9)) ///
>         saving("${mypath}Output/F1/F1_do.gph", replace)
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_do.gph saved)

. 
. graph combine "${mypath}Output/F1/F1_bodfcoli.gph" "${mypath}Outpu
> t/F1/F1_do.gph", rows(1) scheme(s1color)      

. graph export "${mypath}Output/F1/F1_water.eps", replace 
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_water.eps wri
> tten in EPS format)

. graph export "${mypath}Output/F1/F1_water.png", replace 
(note: file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone 
> and Hanna (2014) Replication Files - 01102014\Greenstone and Hanna
>  (2014) Replication Files (non-zipped folder)\Output/F1/F1_water.p
> ng not found)
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_water.png wri
> tten in PNG format)

. 
. ******************************************************************
> *****************
. * 3. Generate Figure 1 for Infant Mortality 
. ******************************************************************
> *****************
. u "${mypath}Data/Water Data/Final Data/india_waters_cityyear.dta",
>  clear

. joinby state city year using "${mypath}Data/Air Data/Final Data/Co
> mbined.dta", unmatched(both)

. joinby state city year using "${mypath}Data/Infant Mortality/IM Ci
> ty/Intermediate Data/cityIMdata.dta", unmatched(both) _merge(_merg
> e2)

. bys state city: egen maxmerge = max(_merge2)

. keep if maxmerge==3
(13439 observations deleted)

. 
. collapse (sum) c_birth c_infantdeath, by(year)

. g india_imr = c_infantdeath*1000 / c_birth
(4 missing values generated)

. 
. /* U.S. Annual means, taken from Joe Shapiro's program 'Estimate_I
> Mpoll2.do' (original data source unknown) */
. g us_imr = 10.4 if year == 1986
(21 missing values generated)

. replace us_imr = 10.1 if year == 1987
(1 real change made)

. replace us_imr = 10.0 if year == 1988
(1 real change made)

. replace us_imr = 9.8 if year == 1989
(1 real change made)

. replace us_imr = 9.2 if year == 1990
(1 real change made)

. replace us_imr = 8.9 if year == 1991
(1 real change made)

. replace us_imr = 8.5 if year == 1992
(1 real change made)

. replace us_imr = 8.4 if year == 1993
(1 real change made)

. replace us_imr = 8 if year == 1994
(1 real change made)

. replace us_imr = 7.6 if year == 1995
(1 real change made)

. replace us_imr = 7.3 if year == 1996
(1 real change made)

. replace us_imr = 7.2 if year == 1997
(1 real change made)

. replace us_imr = 7.2 if year == 1998
(1 real change made)

. replace us_imr = 7.1 if year == 1999
(1 real change made)

. replace us_imr = 6.9 if year == 2000
(1 real change made)

. replace us_imr = 6.8 if year == 2001
(1 real change made)

. replace us_imr = 7 if year == 2002
(1 real change made)

. replace us_imr = 7 if year == 2003
(1 real change made)

. 
. drop if year>2003 & year<1999
(0 observations deleted)

. collapse (mean) india_imr us_imr

. 
. replace india_imr = round(india_imr)
(1 real change made)

. replace us_imr = round(us_imr)
(1 real change made)

. 
. graph bar us_imr india_imr, legend(cols(1) label(1 "United States"
> ) label(2 "India")) scheme(s1color) ///
>         blabel(bar) yscale(range(0 26)) ylab(0 5 10 15 20 25) barg
> ap(5) aspectratio(2) ///
>         ytitle("Mean IMR" "(Deaths/1000 Births)", margin(small)) b
> ar(1, fcolor(gs5) lcolor(gs5)) bar(2,fcolor(black) lcolor(black))

. graph export "${mypath}Output/F1/F1_IM.eps", replace
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_IM.eps writte
> n in EPS format)

. graph export "${mypath}Output/F1/F1_IM.png", replace
(note: file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone 
> and Hanna (2014) Replication Files - 01102014\Greenstone and Hanna
>  (2014) Replication Files (non-zipped folder)\Output/F1/F1_IM.png 
> not found)
(file C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone and Ha
> nna (2014) Replication Files - 01102014\Greenstone and Hanna (2014
> ) Replication Files (non-zipped folder)\Output/F1/F1_IM.png writte
> n in PNG format)

. 
. ******************************************************************
> *****************
. * 4. Clean-up
. ******************************************************************
> *****************
. log close
      name:  <unnamed>
       log:  C:\Users\sberkou\Dropbox\EPoD\NRHM_KARNATAKA\Greenstone
>  and Hanna (2014) Replication Files - 01102014\Greenstone and Hann
> a (2014) Replication Files (non-zipped folder)\Log/Figure1_0110201
> 4.txt
  log type:  text
 closed on:  12 Feb 2014, 14:19:54
--------------------------------------------------------------------
