Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help Translating Factor Analysis Script from SPSS to Stata Syntax

    Hi all,

    I have been tasked with applying a factor analysis to a large data set in Stata. The purpose is to create two indices, aggregated from the survey respondent level (S007) to the country level (S025). I have SPSS syntax and the output achieved using it. However, when trying to translate the SPSS syntax to Stata, I cannot match the output. Here is the SPSS syntax:

    Code:
    MISSING VALUES E003,E004,a008 a165 e018 e025 f063 f118 f120 g006 y002 (-9 to -1).
    MISSING  VALUES y003 (-5).
    EXECUTE.
    WEIGHT by S017.
    execute.
     
    FACTOR  /VARIABLES a008 a165 e018 e025 f063 f118 f120 g006 y002 y003
      /MISSING  PAIRWISE
     /ANALYSIS a008 a165 e018 e025 f063 f118 f120 g006 y002 y003
     /PRINT INITIAL EXTRACTION ROTATION
     /FORMAT SORT BLANK(.3)
     /CRITERIA FACTORS(2) ITERATE(25)
     /EXTRACTION PC
     /CRITERIA ITERATE(25)
     /ROTATION VARIMAX
     /SAVE REG(ALL)
     /METHOD=CORRELATION.
    EXECUTE .
    COMPUTE fac2_1=-fac2_1.
    EXECUTE.
     
    COMPUTE fac1_2= 1.61 * fac1_1- .1 .
    EXECUTE .
    COMPUTE fac2_2= 1.81 * fac2_1+ .038 .
    EXECUTE .
     
    MEANS TABLES=fac1_2 fac2_2 BY S025 /CELLS MEAN.
    I am having particular trouble figuring out how and where to apply the weight (S017, range is from 0.001 to 32.251).
    Last edited by Nicholas Stowell; 27 Oct 2021, 11:31.

  • #2
    what did you write in Stata?

    Comment


    • #3
      Here was my best effort:

      Code:
      foreach v in S025 S017 E003 E004 A008 A165 E018 E025 F063 F118 F120 G006 Y002 {
          replace `v' =. if `v' < 0
      }
      replace Y003 =. if Y003 == -5
      
      factor F063 Y003 F120 G006 E018 Y002 A008 E025 F118 A165, pcf factors (2)
      screeplot
      rotate, varimax
      estat rotatecompare
      
      predict pc1 pc2
      
      replace pc2 = -pc2
      gen pc1_2 = 1.61*pc1 - 0.1
      gen pc2_2 = 1.81*pc2 + 0.038
      
      collapse (mean) pc1_2 pc2_2, by(S025)

      Comment


      • #4
        Code:
         
         factor F063 Y003 F120 G006 E018 Y002 A008 E025 F118 A165 [aw=S017], pcf factors (2)

        Comment


        • #5
          Is there a stata equivalent of :
          Code:
          /MISSING PAIRWISE
          ?

          Comment


          • #6
            Not sure. Imputation may be required.

            Comment


            • #7
              If implementing pairwise deletion is the issue, what about applying -pwcorr- to the variable list, capturing the correlation matrix left behind in r(C) in a Stata matrix, and using the -factormat- command:
              Code:
              pwcorr F063 Y003 F120 G006 E018 Y002 A008 E025 F118 A165
              matrix R = r(C)
              local N = Whatever N SPSS uses with pairwise deletion.
              factormat R, n(`N') pcf factors (2)
              ... etc.

              Comment


              • #8
                Originally posted by Mike Lacy View Post
                If implementing pairwise deletion is the issue, what about applying -pwcorr- to the variable list, capturing the correlation matrix left behind in r(C) in a Stata matrix, and using the -factormat- command:
                Code:
                pwcorr F063 Y003 F120 G006 E018 Y002 A008 E025 F118 A165
                matrix R = r(C)
                local N = Whatever N SPSS uses with pairwise deletion.
                factormat R, n(`N') pcf factors (2)
                ... etc.
                I am unclear on "Whatever N SPSS uses with pairwise deletion".

                Comment


                • #9
                  factormat requires a sample size. I think Mike is saying get the observation count from SPSS.

                  Comment


                  • #10
                    Yes, my idea is that it's unclear as to what the N should be in such an analysis, given that it varies across each pair of variables. SPSS presumably has some solution to that (e.g., the minimum N across all pairs), so if Nicholas wants to reproduce SPSS's results, he presumably could determine what it is doing from the output or documentation in SPSS.

                    Comment


                    • #11
                      It might be useful to post a portion of your sample (using dataex) and show the difference between the SPSS and Stata output. I don't use SPSS so am not in a position to determine exactly what the pairwise deletion is doing.

                      Comment


                      • #12
                        Thank you for the help, gentlemen. I have a friend who tried to reproduce the SPSS output using the raw data and syntax in SPSS in SPSS itself and couldn't, so there is an issue beyond translating the syntax. If I get to the bottom of it I will report back here.

                        Comment

                        Working...
                        X