clear
set more off

version 12 

*******************************
* 1 - Organize stocks returns *
*******************************

use "$temp/Stock prices data", clear

* Add stock indices and business dates
merge n:1 date using "$temp/Stock indices and business dates"
drop _merge

* Generate identifiers and declare time series
egen id = group(ISIN)
tsset id date_business

* Compute returns
gen return = D.price/L.price
gen return_CAC40 = D.index_CAC40/L.index_CAC40
gen return_SBF120 = D.index_SBF120/L.index_SBF120

foreach niveau in "4" "6_Name" {
preserve
ren Industry_Level_`niveau' industry

keep ISIN return* date_business industry

* Save
save "$temp/tmp_stocks_returns_`niveau'", replace
*************************************************

keep ISIN industry
duplicates drop
* Save
save "$temp/tmp_stocks_returns_industries`niveau'", replace
restore
}
