Hi everyone,
I am trying to validate my model. I have 11 models from -50 to +50 in steps of 10. The columns with the model output are named from 'mi50_oc77' to 'mo50_oc81', which means mi (minus) 50 oc (occurrence continuous value from 0 to 1) 77 (year of 1977).
Basically, I have some field data that I will validate my model. The field data contain site name, location, year and status, then I have multiple columns with the output (status) of my model for every location and year.
Here is an example of my data is organised:
location_name latitude longitude year (goes from 1977 to 1981) status mi50_oc77 mi50_oc78 mi50_oc79 up until column mo50_oc81 yearshort loc_1 loc_2 loc_3 loc_4 loc_5 loc_6 loc_7 loc_8 (loc_ is a dummy for location) status_spr (is a dummy for status) location_code
I generated:
gen mi50_correct_yes=. // correct output of my model and the field data (both present)
gen mi50_correct_no=. // correct output of my model and the field data (both absent)
gen mi50_overprediction=. // model overprediction
gen mi50_underprediction=. // model underprediction
I would like to select columns mi50_oc77 up until column mo50_oc81 as my valist.
Then for every single value of valist I would like to apply this code:
forvalues loc=1/8 {
forvalues yr=77/81 {
replace mi50_correct_yes=1 if status==1 & `loc'==location_code & mi50_oc`yr'>0.5 & `yr'==yearshort
replace mi50_correct_no=1 if status==0 & `loc'==location_code & mi50_oc`yr'<0.5 & `yr'==yearshort
replace mi50_overprediction=1 if status==1 & `loc'==location_code & mi50_oc`yr'<0.5 & `yr'==yearshort
replace mi50_underprediction=1 if status==0 & `loc'==location_code & mi50_oc`yr'>0.5 & `yr'==yearshort
replace mi50_correct_yes=0 if mi50_surandap_yes==.
replace mi50_correct_no=0 if mi50_surandap_no==.
replace mi50_overprediction=0 if mi50_surandap_yes_no==.
replace mi50_underprediction=0 if mi50_surandap_no_yes==.
}
}
Currently, I am repeating this loop for every single model (11 times, as I have 11 models). Surely there is a more efficient way to do this.
Could anyone please help with the code? I believe I will have to use foreach going through the valist...
MANY thanks!!!!
I am trying to validate my model. I have 11 models from -50 to +50 in steps of 10. The columns with the model output are named from 'mi50_oc77' to 'mo50_oc81', which means mi (minus) 50 oc (occurrence continuous value from 0 to 1) 77 (year of 1977).
Basically, I have some field data that I will validate my model. The field data contain site name, location, year and status, then I have multiple columns with the output (status) of my model for every location and year.
Here is an example of my data is organised:
location_name latitude longitude year (goes from 1977 to 1981) status mi50_oc77 mi50_oc78 mi50_oc79 up until column mo50_oc81 yearshort loc_1 loc_2 loc_3 loc_4 loc_5 loc_6 loc_7 loc_8 (loc_ is a dummy for location) status_spr (is a dummy for status) location_code
I generated:
gen mi50_correct_yes=. // correct output of my model and the field data (both present)
gen mi50_correct_no=. // correct output of my model and the field data (both absent)
gen mi50_overprediction=. // model overprediction
gen mi50_underprediction=. // model underprediction
I would like to select columns mi50_oc77 up until column mo50_oc81 as my valist.
Then for every single value of valist I would like to apply this code:
forvalues loc=1/8 {
forvalues yr=77/81 {
replace mi50_correct_yes=1 if status==1 & `loc'==location_code & mi50_oc`yr'>0.5 & `yr'==yearshort
replace mi50_correct_no=1 if status==0 & `loc'==location_code & mi50_oc`yr'<0.5 & `yr'==yearshort
replace mi50_overprediction=1 if status==1 & `loc'==location_code & mi50_oc`yr'<0.5 & `yr'==yearshort
replace mi50_underprediction=1 if status==0 & `loc'==location_code & mi50_oc`yr'>0.5 & `yr'==yearshort
replace mi50_correct_yes=0 if mi50_surandap_yes==.
replace mi50_correct_no=0 if mi50_surandap_no==.
replace mi50_overprediction=0 if mi50_surandap_yes_no==.
replace mi50_underprediction=0 if mi50_surandap_no_yes==.
}
}
Currently, I am repeating this loop for every single model (11 times, as I have 11 models). Surely there is a more efficient way to do this.
Could anyone please help with the code? I believe I will have to use foreach going through the valist...
MANY thanks!!!!
Comment