*************************************************************************** *************************************************************************** * * LINKAGE DETERMINISTICO CON VARIABILI A LIVELLO DI PAESE * * un ABBINAMENTO TRA UN FILE DI DATI MICRO E UNO CON DATI MACRO-AGGREGATI *************************************************************************** clear cd "G:\Il mio Drive\Multifonte\" use shareWave1e2 *lavoriamo con le var stringa decode country,gen(country2) br country country2 save shareWave1e2,replace ************************************************************** * UTILIZZIAMO I DATI EUROSTAT SUL GDP DEI PAESI ************************************************************** * gdp = excel file from EUROSTAT * https://ec.europa.eu/eurostat/data/database * -> economy finance -> national accounts * -> annual national accounts -> main GDP aggregates * -> browser * -> selezioniamo gli anni che ci interessano (2004-2010) ************************************************************************ clear import excel gdp_paesi.xlsx, sheet("Sheet 1") firstrow tab TIME *chiamiamo le variabili nello stesso modo di SHARE rename TIME country2 *facciamo un po' di ordine eliminando le colonne vuote drop C E G I K M O *trasformamo il file da wide a long, ossia pił osservazioni per paese rename B gdp_2004 rename D gdp_2005 rename F gdp_2006 rename H gdp_2007 rename J gdp_2008 rename L gdp_2009 rename N gdp_2010 help reshape reshape long gdp_ ,i(country2) j(int_year) save gdp, replace *********************************************************************** merge 1:m country2 int_year using shareWave1e2.dta, gen(_merge3) tab country2 _merge3 if country!=. tab country2 _merge3 if country!=. & interview==1 tab int_year country if _merge3==2 ******************************************************* **l'abbinamento deve essere esatto per le stinghe clear use gdp replace country="Germany" if country2=="Germany (until 1990 former territory of the FRG)" replace country="Czech Republic" if country2=="Czechia" merge 1:m country2 int_year using shareWave1e2.dta ,gen(_merge3) tab country2 _merge3 if country!=. tab country2 _merge3 if country!=. & interview==1 tab int_year country if _merge3==2 tab interview int_year *********************************************************** *********************************************************** * ************* * ESEMPIO 2 * ************* * GDP REGIONALE E DATI MICRO (SHARE) *********************************************************** * partiamo dal file SHARE1-8 dove abbiamo tutte le wave e * i moduli gv_health e gv_housing * da notare che quando abbiamo tanti file da abbinare possiamo /* ricorre ai loop: local vlist 1 2 4 5 6 7 8 local vlist2 dn gv_health gv_housing foreach j of local vlist { use sharew`j'_rel8-0-0_cv_r.dta, clear foreach i of local vlist2 { set more off merge 1:1 mergeid using sharew`j'_rel8-0-0_`i'.dta", drop _merge } * gen WAVE=`j' save "WAVE`j'",replace clear } * */ ********************************************************************************** * MISSING PER COSTRUZIONE : VARIABILI COME LA REGIONE * si assume che gli individui non abbiano cambiato regione nel tempo * possiamo quindi copiare i valori mancanti con i valori che lo stesso individuo * aveva nella wave precedente ********************************************************************************** use SHARE1-8, clear *creiamo un indicatore unico di regione gen nuts=nuts1_2003 replace nuts=nuts1_2010 if nuts=="" replace nuts=nuts1_2015 if nuts=="" sort mergeid WAVE replace nuts=nuts[_n-1] if mergeid==mergeid[_n-1] & nuts=="" tab country WAVE if nuts=="" tab country WAVE if nuts!="" *split string variables split nuts, generate(nuts2) parse("") limit(2) replace nuts21="ITD" if nuts21=="ITH" replace nuts21="ITE" if nuts21=="ITI" replace nuts21="SE1" if nuts21=="SE0" save SHARE1-81,replace ********************************************************************************************************* clear *GDP 2019 2020 by NUTS 1 Regions * LE FONTI SONO IMPORTANTI! esplorare il sito-web: * https://ec.europa.eu/eurostat/databrowser/view/NAMA_10R_2GDP__custom_3775290/default/table?lang=en import excel nama_10r_2gdp__custom_3775290_page_spreadsheet.xlsx, sheet("Sheet 1") ********************************************************************************************************* *che file stiamo importanto in STATA? * teniamo solo i dati *drop rows drop in 1/7 drop in 2 drop in 129/136 *drop columns drop D F H J L drop N P R T V X Z AB AD AF AH AJ tab A tab B gen nuts21=A gen nuts22=B ************************************* replace nuts21="ITD" if nuts21=="ITH" replace nuts21="ITE" if nuts21=="ITI" *no data on Israel and Greece replace nuts21="PL1" if nuts21=="PL7" replace nuts21="PL3" if nuts21=="PL8" replace nuts21="FR2" if nuts21=="FRB" replace nuts21="FR3" if nuts21=="FRD" replace nuts21="FR4" if nuts21=="FRF" replace nuts21="FR5" if nuts21=="FRE" replace nuts21="FR6" if nuts21=="FRJ" replace nuts21="FR7" if nuts21=="FRC" replace nuts21="FR8" if nuts21=="FRM" ************************************* save GDP, replace **************************************** clear use SHARE1-81 merge m:1 nuts21 using GDP **************************************** tab nuts if _merge!=3 drop if _merge==2 gen GDP=C if int_year==2004 replace GDP=E if int_year==2005 replace GDP=G if int_year==2006 replace GDP=I if int_year==2007 replace GDP=K if int_year==2008 replace GDP=M if int_year==2009 replace GDP=O if int_year==2010 replace GDP=Q if int_year==2011 replace GDP=S if int_year==2012 replace GDP=U if int_year==2013 replace GDP=W if int_year==2014 replace GDP=Y if int_year==2015 replace GDP=AA if int_year==2016 replace GDP=AC if int_year==2017 replace GDP=AE if int_year==2018 replace GDP=AG if int_year==2019 replace GDP=AI if int_year==2020 replace GDP="." if GDP==":" destring GDP,gen(GDP1) drop A-AI ************************************************************ ************************************************************ * * ORA POTREMMO FARE DELLE ANALISI CON DATI GERARCHICI * O DELLE ANALISI A LIVELLO TERRITORIALE * ************************************************************ encode nuts21,gen(NUTS) bys NUTS WAVE: egen mean_maxg=mean(maxgrip) scatter mean_maxg GDP1 if mean_maxg<45, connect(none) scatter mean_maxg GDP1 if mean_maxg<45 || lfit mean_maxg GDP1 if mean_maxg<45, ***** * Modello Multilevel con intercetta Random mixed maxgrip i.WAVE i.gender if GDP1!=. || NUTS: ***** * Modello Multilevel dove aggiungiamo il PIL regionale mixed maxgrip i.WAVE i.gender GDP1 || NUTS: *valori predetti predict score_grip1 if e(sample), fitted scatter score_grip1 GDP1 || lfit score_grip GDP1,by(gender) *********************************************************** *********************************************************** * ************* * ESERCIZIO * ************* * PROVATE AD ABBINARE LE INFORMAZIONI CONTENUTE NEL FILE * SHARE WAVE 8 (COVID INTERVIEW) CON LE INFORMAZIONI * COVID-19 Government Response Tracker (Oxford: * https://www.bsg.ox.ac.uk/research/research-projects/covid-19-government-response-tracker * contenute nel file excel Excel OxCGRT ************************************************************ ************************************************************ import excel OxCGT stringency_index.xls, sheet("Sheet1") firstrow rename Gennaio pcovid_1 rename Febbraio pcovid_2 rename Marzo pcovid_3 rename Aprile pcovid_4 rename Maggio pcovid_5 rename Giugno pcovid_6 rename Luglio pcovid_7 rename Agosto pcovid_8 rename Settembre pcovid_9 rename Ottobre pcovid_10 rename Novembre pcovid_11 rename Dicembre pcovid_12 reshape long pcovid_ ,i(country_name) j(int_year) save oxf,replace clear use oxf rename int_year int_month save oxf,replace use sharew8_rel8-0-0_cv_r decode country, gen(country_name) merge m:1 country_name int_month using oxf tab country if interview==1 & _merge==1 clear use sharew8_rel8-0-0_cv_r decode country, gen(country_name) replace country_name="Slovak Republic" if country_name=="Slovakia" merge m:1 country_name int_month using oxf