Hello,
I am currently analysing a dataset containing firm data such as Total assets and the tax rate of the country the company resides in. In order to analyse the income shifting behaviour of these firms, the literature presents one variable (here called C) which has to be calculated.
This variable C consists for each observations in its denominator of a sum over all observations. The basic format of what has to summed is: TA[j] * (STR[i] - STR[j]) with i being the current observation and j the other observation. This formula has to be summed up for each observation over all observations without j = i.
I have tried this with a loop:
local n = _N
gen nomi_C = .
forvalues i = 1/`n' {
gen double temp_sum = 0
forvalues j = 1/`n' {
if `j' != `i' {
replace temp_sum = temp_sum + TA[`j'] * (STR[`i'] - STR[`j'])
}
}
replace nomi_C = temp_sum in `i'
}
As the dataset consists of roughly 90,000 observations, this loop took over 8 h and still was not finished.
I am now wondering whether that is normal to take so long and whether there is a faster way to complete the described problem.
Thank you very much in advance!
Best,
Katharina
I am currently analysing a dataset containing firm data such as Total assets and the tax rate of the country the company resides in. In order to analyse the income shifting behaviour of these firms, the literature presents one variable (here called C) which has to be calculated.
This variable C consists for each observations in its denominator of a sum over all observations. The basic format of what has to summed is: TA[j] * (STR[i] - STR[j]) with i being the current observation and j the other observation. This formula has to be summed up for each observation over all observations without j = i.
I have tried this with a loop:
local n = _N
gen nomi_C = .
forvalues i = 1/`n' {
gen double temp_sum = 0
forvalues j = 1/`n' {
if `j' != `i' {
replace temp_sum = temp_sum + TA[`j'] * (STR[`i'] - STR[`j'])
}
}
replace nomi_C = temp_sum in `i'
}
As the dataset consists of roughly 90,000 observations, this loop took over 8 h and still was not finished.
I am now wondering whether that is normal to take so long and whether there is a faster way to complete the described problem.
Thank you very much in advance!
Best,
Katharina
Comment