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

Re: st: creating a foreach loop for principal components

 From Dmitriy Glumov To statalist@hsphsun2.harvard.edu Subject Re: st: creating a foreach loop for principal components Date Mon, 5 Sep 2011 12:19:23 -0400

```Nick,

Thank you for your help, this is exactly what I was looking for, and
sorry for the potential confusion in my question.

Regards,
Dmitri

On Fri, Sep 2, 2011 at 2:09 PM, Dmitriy Glumov <glumovdm@gmail.com> wrote:
> 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
>
> Regards,
> Dmitri
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```