Hi,
I have a dataset that looks like this (also see attachment):
The four min/max variables are calculated as follows:
gen x_min = x_koord-1
gen x_max = x_koord+1
gen y_min = y_koord-1
gen y_max = y_koord+1
Now I want to create a new variable that sums the column "area" conditional on the four calculated variables listed above.
The new variable should take the sum of the variable "area" if (x_min <= x_koord <= x_max) & (y_min <= y_koord <= y_max)
I tried using this formula (but it didn't work):
egen total = sum(area) if (x_min <= x_koord <= x_max) & (y_min <= y_koord <= y_max)
(I am more used to working in Excel, where it could have been solved using a SUMIFS formula)
Any suggestions on how to make this work in Stata?
Thanks in advance.
/Soeren
I have a dataset that looks like this (also see attachment):
ID | area | x_koord | y_koord | x_min | x_max | y_min | y_max |
100m_61570_4423 | 115 | 4423 | 61570 | 4422 | 4424 | 61569 | 61571 |
100m_61571_4423 | 291 | 4424 | 61571 | 4423 | 4425 | 61570 | 61572 |
The four min/max variables are calculated as follows:
gen x_min = x_koord-1
gen x_max = x_koord+1
gen y_min = y_koord-1
gen y_max = y_koord+1
Now I want to create a new variable that sums the column "area" conditional on the four calculated variables listed above.
The new variable should take the sum of the variable "area" if (x_min <= x_koord <= x_max) & (y_min <= y_koord <= y_max)
I tried using this formula (but it didn't work):
egen total = sum(area) if (x_min <= x_koord <= x_max) & (y_min <= y_koord <= y_max)
(I am more used to working in Excel, where it could have been solved using a SUMIFS formula)
Any suggestions on how to make this work in Stata?
Thanks in advance.
/Soeren
Comment