Announcement

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

  • Prefix ‘by’ when running post-estimation statistics for a PCA

    Hi
    I have a question regarding the use of the prefix ‘by’ when running post-estimation statistics for a PCA.

    My data consists of 25 items, three different respondents (parent, teacher, child) and two different age groups (cohort 1 and cohort 2). I would like to run a PCA and post-estimation for each of the six sub-groups (respondent x time). The code for the PCA (below) ran successfully providing me with 6 different outputs.

    by Respondent cohort, sort: pca Item1- Item25, mineigen(1)

    However, when I run the post estimation tests (rotate and estat KMO) I only receive post estimation statistics for the last respondent x cohort group generated from the above PCA. Below is my code for the PCA and post estimation tests.

    by Respondent cohort, sort: pca Item1- Item25, mineigen(1)
    quietly rotate
    estat rotatecompare
    estat kmo, novar

    Alternatively I could use the ‘if’ command after the PCA and generate 6 blocks of code (see below) however I would prefer to run the all data together rather than running each individually.

    pca Item1- Item25, mineigen(1), if Respondent==1 & cohort==1
    quietly rotate
    estat rotatecompare
    estat kmo, novar
    pca Item1- Item25, mineigen(1), if Respondent==1 & cohort==2
    quietly rotate
    estat rotatecompare
    estat kmo, novar
    .
    .
    etc

    I am currently using version 15.1

    Thanks in advance for your time.
    Last edited by Jen Walker; 14 Mar 2019, 18:13.

  • #2
    You could do this:
    Code:
    capture program drop one_group
    program define one_group
        display "Respondent #" Respondent " Cohort #" cohort
        pca Item1- Item25, mineigen(1)
        quietly rotate
        estat rotatecompare
        estat kmo, novar  
        exit
    end
    
    runby one_group, by(Respondent cohort) verbose
    -runby- is written by Robert Picard and me and is available from SSC.

    Unsolicited advice: the use of -if- in the commands you show is the -if- qualifier or -if- condition. The -if- command exists in Stata and is something different. It is important not to confuse the two, as they do rather different things.
    Last edited by Clyde Schechter; 14 Mar 2019, 18:18. Reason: Modify code so that output is labeled with current values of Respondent and cohort.

    Comment


    • #3
      That has worked perfect - thank you so much.

      Also thanks for the additional advice regarding 'if' - I am new to Stata so these clarifications are important.

      Thanks again!

      Comment

      Working...
      X