Announcement

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

  • Saving/Storing Principal Components

    Hey everybody,

    I'm doing a principal component analysis and I need to store the coefficients of my two principal components in order to be able to continue calculating with them and to use them as weights. How can I do that? Below you see the PCA output I get in STATA, I need to save Comp1 and Comp2 as a variable in order to square them, sum them up etc. Thanks so much for your help.

    Best regards,

    Peter
    I need to save Comp1 and Comp2 as a variable.

  • #2
    First consider whether you actually need the coefficients. If you just want to calculate the values of the components so you can use those for later calculations, -predict- after -pca- will do that for you. You will only need the coefficients if they are specifically of interest in your project, or if you will need to use them to calculate component scores for other data.

    That said, if you really do need the coefficients, after -predict-, the matrix of coefficients is saved in r(scoef). Like all r() results, these are volatile, and so you should copy them into a real matrix.

    Code:
    pca list_of_your_variables_here
    
    predict comp // CREATES VARIABLES comp* CONTAINING COMPONENT SCORES
    
    matrix M = r(scoef) // RETAINS COEFFICIENTS IN A MATRIX
    For the future, please don't post screen shots. Yours was barely readable on my computer; in reality I was able to help you with this only because I didn't really need to see what was in it. Screenshots are often completely unreadable. Even when they are easily read, though, you can't copy and paste from them if you need to use that information. The most helpful way to show Stata output is to copy from the Results window or your log file and paste directly into a code block. If you don't know how to set up a code block, you can find the instructions in FAQ #12.

    Comment


    • #3
      Dear Clyde,

      Thanks so much for your answer. The thing is that I'm using the coefficients as weights for the individual indicators. In fact, I'm aggregating components 1 and 2 using weights corresponding to the share of variation explained. Does that make sense? Thanks for the solution as well as for the tips.

      Best regards,

      Peter

      Comment


      • #4
        pcacoefsave from SSC may help. See http://www.statalist.org/forums/foru...-for-pca-users

        In addition to Clyde's good advice, see also http://www.statalist.org/forums/help#spelling
        Last edited by Nick Cox; 27 Feb 2016, 11:26.

        Comment


        • #5
          Thanks, Nick!

          Comment

          Working...
          X