Announcement

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

  • PCA by variable

    Hi all,

    I'm trying to do a Principal Component Analysis. The dataset I'm using is the PIAAC dataset from the OECD.

    What I'm trying to do is to get just the first component results of a varlist, however I want to see the differences between jobsectors (53 sectors) as described in one of my variables.

    So every individual has filled out the sector he/she works in and has filled out several skills he /she needs this, is my varlist as used in the pca, now I would like stata to list all first component results per ISCO level, also I would like stata to generate a new variable that gives the first component result per individual per ISCO level.

    I don't believe i have to manually run my pca like this for all sectors (ISCO08_C) manually:

    pca ReadingArticles ReadingNewsletters ReadingProfessionalJournals ReadingDiagrams ///
    Emails Reports Fractions Calculator Charts Algebra ComplexProb Manage Presentation ///
    Advising PlanOther Influence Negotiating if ISCO08_C == 11

    Is there a way I can do all this automatically instead of 53 separate commands for every sector.

    Kind regards,

    Jules

  • #2
    Welcome to Statalist!

    Here's a start at what you want, if I understand your needs correctly.
    Code:
    levelsof ISCO08_C, local(sectorlist)
    foreach sector of local sectorlist {
    pca ReadingArticles ReadingNewsletters ReadingProfessionalJournals ReadingDiagrams ///
    Emails Reports Fractions Calculator Charts Algebra ComplexProb Manage Presentation ///
    Advising PlanOther Influence Negotiating if ISCO08_C == `sector'
    }
    The wording of your question suggests you are perhaps unfamiliar with looping in Stata, of which my code is a very basic example. If so, let me share this advice I often pass out. When I began using Stata in a serious way, I started by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through Stata's Help menu. The objective in doing this was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax.

    Stata supplies exceptionally good documentation that amply repays the time spent studying it.

    Comment


    • #3
      Hi Thanks for replying! I have read a lot on the beginning use of stata however I still wasn't able to find out whether it is possible to generate a table just stating the first components or better generate a new variable with all the first components as given by all these PCA's. Right now Im receiving too much information and I have been manually going through it noting all the first components per sector. I'm not sure how to create a new variable per sector using the first component as value. It would be much appreciated if someone could point me in the right direction.

      Kind regards,

      Jules

      Comment


      • #4
        predict after pca puts the values of components into variables. The first component (there is only one first component; I don't know where the plural comes from) will be put in the first variable named.

        Code:
         
        sysuse auto, clear 
        pca weight trunk length headroom displacement 
        predict pc1
        It seems that your project is one step more complicated in doing this repeatedly but that is just a matter of selecting observations.

        Comment

        Working...
        X