Using Stata version 18.
Hi All, I have a straightforward question. I have a dataset with just 24 rows that I am trying to calculate risk ratios with 95% CI's.
Here is the direct command I use:
csi 54227 250552 27476 227947 // this gives me what I want. Risk ratios with upper and lower bound 95% CI estimates. If I type return list after this, I see that the values are stored in r(rr), r(lb_rr) and r(ub_rr)
But then when I attempt to replace a variable I've created with a stored value from this command using this code:
replace lowerbound[1] = r(lb_rr)
I get this error:
"weights not allowed
r(101);"
I'm actually running the code in a loop for each observation. But after the first row of data, I get this error message above. So I just tried using direct commands with the first observation and get the same message.
If this is more helpful to see some rows of data:
Here is my code using the loop that produces the same error message:
clear
set more off
use raw_prev_any_merged
gen risk_ratio = .
gen lowerbound = .
gen upperbound = .
forvalues i = 1/`=_N' {
local aw = any_mski_women[`i']
local am = any_mski_men[`i']
local nw = women_no_anymski[`i']
local nm = men_no_anymski[`i']
csi `aw' `am' `nw' `nm'
* Store the results in the new variables
replace risk_ratio[`i'] = r(rr)
replace lowerbound[`i'] = r(lb_rr)
replace upperbound[`i'] = r(ub_rr)
}
Thanks for any help!
Ben
Hi All, I have a straightforward question. I have a dataset with just 24 rows that I am trying to calculate risk ratios with 95% CI's.
Here is the direct command I use:
csi 54227 250552 27476 227947 // this gives me what I want. Risk ratios with upper and lower bound 95% CI estimates. If I type return list after this, I see that the values are stored in r(rr), r(lb_rr) and r(ub_rr)
But then when I attempt to replace a variable I've created with a stored value from this command using this code:
replace lowerbound[1] = r(lb_rr)
I get this error:
"weights not allowed
r(101);"
I'm actually running the code in a loop for each observation. But after the first row of data, I get this error message above. So I just tried using direct commands with the first observation and get the same message.
If this is more helpful to see some rows of data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long(any_mski_men any_mski_women) float(men_no_anymski women_no_anymski) 250552 54227 227947 27476 136817 39467 141022 28017 74313 9434 120931 7484 95684 28828 199172 40146 242151 54565 226788 27570 140070 40801 141758 29233 76117 10053 119678 7897 94493 29316 197814 41257 240411 55013 229212 28960 142652 42698 140726 29485 79491 10725 114697 7667 96589 30997 197036 41827 242143 55744 223708 28728 143613 44352 142019 30956 82938 11639 112481 7526 101319 33652 194852 41547 219516 53927 248417 32912 124985 40757 159674 35876 75929 10832 117494 8223 91632 32534 208484 45125 220248 53517 246776 32534 120433 40891 165301 37124 79827 11120 111046 7839 97199 34405 206582 45034 end
clear
set more off
use raw_prev_any_merged
gen risk_ratio = .
gen lowerbound = .
gen upperbound = .
forvalues i = 1/`=_N' {
local aw = any_mski_women[`i']
local am = any_mski_men[`i']
local nw = women_no_anymski[`i']
local nm = men_no_anymski[`i']
csi `aw' `am' `nw' `nm'
* Store the results in the new variables
replace risk_ratio[`i'] = r(rr)
replace lowerbound[`i'] = r(lb_rr)
replace upperbound[`i'] = r(ub_rr)
}
Thanks for any help!
Ben
Comment