Created
March 6, 2020 19:47
-
-
Save bbdaniels/bbd547d7b333d0863825701f7a4d2806 to your computer and use it in GitHub Desktop.
Loadings graph with arbitrary components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get arbitrary loadings | |
// Data | |
sysuse auto.dta , clear | |
local variables length mpg price rep78 | |
// Get labels | |
foreach var of varlist `variables' { | |
local `var' : var label `var' | |
} | |
// Do PCA | |
pca `variables' | |
// Get loadings | |
estat loadings | |
mat loadings = r(A) | |
// Load loadings as data | |
clear | |
svmat loadings | |
// Label loadings | |
local x = 0 | |
gen label = "" | |
foreach var in `variables' { | |
local ++x | |
replace label = "``var''" in `x' | |
} | |
// Graph | |
tw scatter loadings1 loadings3 , mlab(label) | |
// End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment