Hi. I am trying to run a ttest on a local of multiple variables, but am getting the error "command ttest exited with an error when run using the entire sample". However, when I run the same command individually on variables in the local "vars" the command runs pererctly. Can someone please help me here. Thank you.
Code:
local myresults "Control = r(mu_1) Treated = r(mu_2) Diff = (r(mu_2)-r(mu_1)) pvalue = r(p)" display "`myresults'" #delimit ; local vars pop_perkm2_2019 per60_2011 per85_2011 deathrate_2019 povertyperct /// malariacase2018 denguecase2018 typoidtot_case2018 exphealth_percap1516 /// acuteresp_totcase2018 pneumoniatot_case2018 tb2018 influenzacase_2018 hepcases_2018 /// diabetes20181k hypertension20181k htnanddm20181k cvds20181k /// stroke20181k hepcases_20181k commoncancers20181k mentalillness_20111k /// hospital_total1k hospital_beds_total1k icu_beds_total1k ventilators_total1k /// ; #delimit cr display "`vars'" . foreach x of local vars { 2. di "`x'" 3. table (command) (result),command(`myresults' : ttest `v'', by(stepone)) 4. nformat(%6.2f Control Treated Difference) 5. nformat(%6.0f pvalue) 6. } pop_perkm2_2019 command ttest exited with an error when run using the entire sample r(198); end of do-file
Comment