Hello
I want to run group comparison using basic inference using t-test and others methods mentioned in the code.
When I use only one test at a time in the loop, it works fine as shown in first segment. But when I make the test over the loop, it works fine till producing results but fail to write to post_file so I cant export the results readily to Excel.
The two code, working example and not working example, is attached below. Your comments and suggestions on second part is requested so it works and be able to export the results to Excel.
Thanks in advance.
************************************************** *******************
****Example does work
************************************************** *******************
clear
use "data.dta", clear
tempname anees_ttest
tempfile ttests
postfile `anees_ttest' str12 name t_statistic using `ttests'
foreach var of varlist Names go here {
ttest `var', by(group)
post `anees_ttest' ("`var'") (r(t))
}
postclose `anees_ttest'
clear
use `ttests'
list
export excel using "E:\Stata\export.xls", firstrow(variables) replace
************************************************** *******************
****Example does not working
************************************************** *******************
clear
use "data.dta", clear
tempname anees_ttest
tempfile ttests
postfile `anees_ttest' str12 name t_statistic shapiro_wilk rank_rum pearson_chi2 fisher_chi2 using `ttests'
foreach var of varlist Names go here {
ttest `var', by(group)
swilk `var'
ranksum `var', by(group)
median `var', by(group)
median `var', by(group) exact
post `anees_ttest' ("`var'") (r(t)) (r(W)) (r(z)) (r(chi2)) (r(chi_cc))
}
postclose `anees_ttest'
clear
use `ttests'
list
export excel using "E:\Stata\export.xls", firstrow(variables) replace
************************************************** *******************
****Example Ends
************************************************** *******************
Regards
---------------------------
Muhammad Anees
Assistant Professor
COMSATS Institute of Information Technology
Near Officers Colony, Kamra Road
Attock 43600, Pakistan
elearning(.)aneconomist(.)com
I want to run group comparison using basic inference using t-test and others methods mentioned in the code.
When I use only one test at a time in the loop, it works fine as shown in first segment. But when I make the test over the loop, it works fine till producing results but fail to write to post_file so I cant export the results readily to Excel.
The two code, working example and not working example, is attached below. Your comments and suggestions on second part is requested so it works and be able to export the results to Excel.
Thanks in advance.
************************************************** *******************
****Example does work
************************************************** *******************
clear
use "data.dta", clear
tempname anees_ttest
tempfile ttests
postfile `anees_ttest' str12 name t_statistic using `ttests'
foreach var of varlist Names go here {
ttest `var', by(group)
post `anees_ttest' ("`var'") (r(t))
}
postclose `anees_ttest'
clear
use `ttests'
list
export excel using "E:\Stata\export.xls", firstrow(variables) replace
************************************************** *******************
****Example does not working
************************************************** *******************
clear
use "data.dta", clear
tempname anees_ttest
tempfile ttests
postfile `anees_ttest' str12 name t_statistic shapiro_wilk rank_rum pearson_chi2 fisher_chi2 using `ttests'
foreach var of varlist Names go here {
ttest `var', by(group)
swilk `var'
ranksum `var', by(group)
median `var', by(group)
median `var', by(group) exact
post `anees_ttest' ("`var'") (r(t)) (r(W)) (r(z)) (r(chi2)) (r(chi_cc))
}
postclose `anees_ttest'
clear
use `ttests'
list
export excel using "E:\Stata\export.xls", firstrow(variables) replace
************************************************** *******************
****Example Ends
************************************************** *******************
Regards
---------------------------
Muhammad Anees
Assistant Professor
COMSATS Institute of Information Technology
Near Officers Colony, Kamra Road
Attock 43600, Pakistan
elearning(.)aneconomist(.)com
Comment