Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: creating a foreach loop for principal components

From   Dmitriy Glumov <[email protected]>
To   [email protected]
Subject   st: creating a foreach loop for principal components
Date   Fri, 2 Sep 2011 14:09:30 -0400

Dear Statalist Users,

I am working on principal components and have run into a problem
creating a loop. I have about 300 observations and each one needs to
undergo a 3 step process: 1) Creating principal components WITHOUT the
respective observation (principal components function itself is very
simple, but I struggle to create a loop for it), 2) Predicting first 5
components (this step doesn't change, but component values themselves
are dependent on step 1), and 3) Regressing the respective variable
onto the components.

To illustrate, the process for variable 1 would look something like this:
pca var2-var300
predict pc1-pc5
regress var1 pc1-pc5

For variable 2, it would be this:

pca var1 var3-var300
predict pc1-pc5
regress var2 pc1-pc5

For variable 3,

pca var1-var2 var4-var300
predict pc1-pc5
regress var3 pc1-pc5

and, so on for the remaining variables. It is certainly doable by
hand, but the process is very time-consuming. I am sure there is a way
to create a foreach loop but I just can't figure out how. So if you
can help me with this, it would be greatly appreciated. Thank you for
your consideration.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index