Search code examples
pythonstatafactor-analysis

Factor Analysis in Python and Stata


I have a dataset with 29 items to be run Exploratory Factor Analysis. I have implemented this dataset with the same factors in both Python and Stata, but I have two different results. Actually they are different since I identified the eigenvalues: in Python it is 4 but in Stata only 2.

Why are there such differences and which result should I take? Here are my codes Python

df = df[df.g1 == 3]
fa = FactorAnalyzer()
fa.set_params(n_factors=6) # so factor
fa.fit(df)
fa.loadings_
fa_loading_df = pd.DataFrame(fa.loadings_, columns=['Factor 1', 'Factor 2', 'Factor 3', 'Factor 4', 'Factor 5', 'Factor 6'])

Stata

factor k2x1-k2x29 if g1==3, factor(6)
rotate, varimax norm blanks(.40)

Results


Solution

  • You need to understand what type of exploratory factor analysis (EFA) each command performs, and what type YOU want it to perform. There are multiple types of EFA, such as principal factor, principal component factor, ML etc.

    My guess Python and Stata have different default methods, hence you get different results. In your commands, you don't specify the method to be used, hence the default methods is used.

    In Stata, the default is principal factor, while in Python, my guess is the default is minres, according to this web: https://factor-analyzer.readthedocs.io/en/latest/factor_analyzer.html