Dear Statalists,
My goal is to create daily temperature data for several regions.
I have daily temperature data for several cities and villages which I try to aggreate to the regional level. I have 100 regions. To accomplish that I have calculated distances between the center of each region and every city or village, which resulted in 100 variables that contain distances between the regional center and every village or city. Now I would like to compute regional temperature averages, in which every village or city that lies within a certain distance contributes to the average. I also require that the further away a place is from its centroid, the lower should be the contribution to the average regional temperature.
That worked fine and the results are stored in the temp_cleaned_2009.dta file, which I then use to compute the inverse--weights and the inverse--weighted temperatures. So far, everything worked fine. When I try to collapse the weighted temperatures and the inverse weights in order to obtain their sums and hence eventually their daily averages, STATA SOMETIMES responds that 'no observations' exist.
Particularly, if I only apply collapse to one variable, it works fine. Sometimes it also works for two variables. I have attached my code to this post.
Maybe it also helps to know that the variables ContributionTemp and InverseWeight contain many missing values due to the distance truncation.Moreover, I already checked that none of the variables are actually strings. All of the relevant variables are floats.
Any helpful comments would be greatly appreciated.
Martin
use temp_cleaned_2009, clear
forvalues i = 1/75{
generate DistanceDummy`i' = 0
replace DistanceDummy`i' = 1 if Distance`i' < 100
generate WithinDistance`i' = DistanceDummy`i' * Distance`i'
generate InverseWeight`i' = 1/WithinDistance`i'
generate ContributionTemp`i' = temperature * InverseWeight`i'
drop WithinDistance`i'
drop DistanceDummy`i'
}
collapse (sum) ContributionTemp1-ContributionTemp75 InverseWeight1-InverseWeight75, cw by(date)
My goal is to create daily temperature data for several regions.
I have daily temperature data for several cities and villages which I try to aggreate to the regional level. I have 100 regions. To accomplish that I have calculated distances between the center of each region and every city or village, which resulted in 100 variables that contain distances between the regional center and every village or city. Now I would like to compute regional temperature averages, in which every village or city that lies within a certain distance contributes to the average. I also require that the further away a place is from its centroid, the lower should be the contribution to the average regional temperature.
That worked fine and the results are stored in the temp_cleaned_2009.dta file, which I then use to compute the inverse--weights and the inverse--weighted temperatures. So far, everything worked fine. When I try to collapse the weighted temperatures and the inverse weights in order to obtain their sums and hence eventually their daily averages, STATA SOMETIMES responds that 'no observations' exist.
Particularly, if I only apply collapse to one variable, it works fine. Sometimes it also works for two variables. I have attached my code to this post.
Maybe it also helps to know that the variables ContributionTemp and InverseWeight contain many missing values due to the distance truncation.Moreover, I already checked that none of the variables are actually strings. All of the relevant variables are floats.
Any helpful comments would be greatly appreciated.
Martin
use temp_cleaned_2009, clear
forvalues i = 1/75{
generate DistanceDummy`i' = 0
replace DistanceDummy`i' = 1 if Distance`i' < 100
generate WithinDistance`i' = DistanceDummy`i' * Distance`i'
generate InverseWeight`i' = 1/WithinDistance`i'
generate ContributionTemp`i' = temperature * InverseWeight`i'
drop WithinDistance`i'
drop DistanceDummy`i'
}
collapse (sum) ContributionTemp1-ContributionTemp75 InverseWeight1-InverseWeight75, cw by(date)
Comment