0

I have a dataset with several independent variables and few dependent variables I'd like to run multiple t-tests with. All my independent are dummies, whereas my dependent vars are numeric.

I wrote the following loop:

for ind in df[['ind1','ind2', 'ind3','ind4','ind5']]:
    for dep in df[['dep1', 'dep2', 'dep3', 'dep4']]:
        cat1 = df[df[ind]==1][dep]
        cat2 = df[df[ind]==0][dep]
        print(ttest_ind(cat1, cat2, equal_var=False))

I run the code but the script does not print the result (not sure why..). Also, I would like to store the difference and the p-values in a dataframe so to graph them later.. how to do it? thanks!

Filippo Sebastio
  • 1,112
  • 1
  • 12
  • 23

1 Answers1

0

I managed it!

pvalue = []
ttest = []
deplist = []
indlist =[] 

for ind in monthly[['indvar1', 'indpvar2', 'indpvar3'...]]:
    for dep in monthly[['depvar1', 'depvar2'....]]:
        cat1 = monthly[monthly[ind]==1][dep]
        cat2 = monthly[monthly[ind]==0][dep]
        a, b = ttest_ind(cat1, cat2, equal_var=False)
        indlist.append(ind)
        deplist.append(dep)
        ttest.append(a)
        pvalue.append(b)
Filippo Sebastio
  • 1,112
  • 1
  • 12
  • 23