**	THIS FILE PREPARE THE SURVEY DATA FOR VALIDATION


	clear
	set mem 200m

** 	CHANGE THE DIRECTORY
	cd $DIR

** USE SURVEY DATA

	use survey, clear
	gen D_1 = 1 if Builsa  ==1
	gen D_2 = 2 if Kassena ==1
	gen D_3 = 3 if Bongo  ==1
	gen D_4 = 4 if Bolga  ==1
	gen D_5 = 5 if BawkuW  ==1
	gen D_6 = 6 if BawkuM  ==1
	gen D_7 = 7 if Talensi  ==1
	gen D_8 = 8 if GaruTemp  ==1

	egen DistID= rsum(D_*)
	drop D_* _merge

** 	KEEP ONLY THE DISTRICTS IN ATANKWIDI CATCHMENT

	drop if DistID>4
	**keep if DistID==2

	rename cid clustID

	keep run clustID aID Onion_Land Toma_Land SoMi_Land Gnut_Land Maize_Land Beans_Land Rice_Land MiBeGn_Land
	
	rename Onion_Land sarea_onion
	rename Toma_Land sarea_tomato
	rename SoMi_Land sarea_millet
	rename Gnut_Land sarea_groundnut
	rename Maize_Land sarea_rfmaize
	rename Rice_Land sarea_rice
	rename MiBeGn_Land sarea_Mil_beans_gnut
	rename Beans_Land sarea_beans


	keep sarea_*  clustID 

** 	CALCULATE THE AVERAGE OVER THE PERIODS
	collapse (mean) sarea_* ,by (clustID) fast

** 	RESHAPE TO CROPS
	reshape long sarea_ ,i(clustID) j(crop) string
	rensfix _

** 	COLLAPSE TO THE CROP LEVEL
	collapse (sum) sarea, by(crop) fast
	
**	RENAME CROPS
	g str18 cropname = "."
	replace cropname = "Rice" 			if crop == "rice"
	replace cropname = "Irrigated Rice" 	if crop == "irice"
	replace cropname = "Rainfed Rice" 		if crop == "rfrice"
	replace cropname = "Goundnut Beans" 			if crop == "gnut_bean"
	replace cropname = "Groundnut" 		if crop == "groundnut"
	replace cropname = "Irrigated Maize" 		if crop == "irmaize"
	replace cropname = "Onion" 		if crop == "onion"
	replace cropname = "Tomato" 		if crop == "tomato"
	replace cropname = "Sup Irrigated Rice" 		if crop == "sprice"
	replace cropname = "Rainfed Maize" 		if crop == "rfmaize"
	replace cropname = "Millet Beans" 		if crop == "mil_bean"
	replace cropname = "Millet" 		if crop == "millet"
	replace cropname = "Beans" 		if crop == "beans"
	replace cropname = "Mil+be+GN" 		if crop == "Mil_beans_gnut"


	save survey_croparea, replace
