My question is similar to R: using predict() on new data with high dimensionality but for Stata
I want to run a principal components model (pca) on one subset of data (the control group from an experiment) to extract the first component. Then I want to re-run the PCA model on a separate subset of data (the treatment group from an experiment) and get scores for those data as well. Essentially I want to use a pca model run on dataset_1 to predict scores in a new dataset_2.
In R, one would fit the model to the control group only, then one would use the "predict" command on the fitted model, with the full data set in the "new data" argument. This would generate predictions for all observations from a model fitted on the control group only. However, how does one do this in Stata?
global xlist2a std_agreedisagree1_1_a std_revagreedisagree1_2_a std_revagreedisagree1_3_a std_agreedisagree1_4_a std_revagreedisagree1_10_a std_revagreedisagree1_5_a
pca $xlist2a
screeplot, yline(1)
rotate, clear
pca $xlist2a, com(3)
rotate, varimax blanks (.30)
predict pca5_p1b pca5_p2b pca5_p3b, score
Fixed code based on Nick's answer:
global xlist2a std_agreedisagree1_1_a std_revagreedisagree1_2_a std_revagreedisagree1_3_a std_agreedisagree1_4_a std_revagreedisagree1_10_a std_revagreedisagree1_5_a
pca $xlist2a if zgroupa10==1
screeplot, yline(1)
rotate, clear
pca $xlist2a if zgroupa10==1, com(3)
rotate, varimax blanks (.30)
predict pca5_p1b pca5_p2b pca5_p3b, score
pca
on all the observations for certain variables and thenpredict
on all the observations. That's not what you should do, but your comment below my answer implies that your real code applied the approach needed. – Nick Cox