Are you saying that my code doesn't work in 14.2?
Code:
gen str5 prop_lbl = string(proportion, "%03.2f") gen str5 cum_lbl = string(cumulative, "%03.2f")
(Ridwan)
gen str5 prop_lbl = string(proportion, "%03.2f") gen str5 cum_lbl = string(cumulative, "%03.2f")
sysuse auto, clear pca length weight headroom trunk displacement mat Ev = e(Ev) local J = colsof(Ev) gen eigenvalue = Ev[1, _n] in 1/`J' gen eigen_prop = strofreal(eigenvalue/`J', "%03.2f") in 1/`J' gen PC = _n in 1/`J' gen Cumulative = sum(eigenvalue) in 1/`J' capture set scheme stcolor if _rc { set scheme s1color local stretch ysc(r(. `J'.2)) } local colour1 = cond(c(version) >= 18, "stc1", "blue") local colour2 = cond(c(version) >= 18, "stc2", "red") * mylabels is from Stata Jouranl mylabels 0.2(0.2)0.8, myscale(`J' * @) format(%02.1f) local(yla) gen Cumulative_show = strofreal(Cumulative/`J', "%03.2f") list eigenvalue eigen_prop Cumulative PC in 1/`J' screeplot , recast(bar) mla(eigen_prop) mlabpos(12) barw(0.8) lcol(`colour1') fcol(`colour1'*0.2) /// addplot( /// connected Cumulative PC, mla(Cumulative_show) mlabc(`colour2') mlabpos(12) /// ) /// legend(pos(12) row(1)) yaxis(1 2) /// yla(`yla' 0 `J' "1", ang(h) axis(2) labcolor(`colour2')) /// yla(, ang(h) axis(1) labcolor(`colour1')) /// ytitle(Cumulative Proportion, axis(2) color(`colour2')) /// ytitle(Eigenvalues, axis(1) color(`colour1')) xtitle(PC) `stretch'
* mylabels is from Stata Journal
sysuse auto, clear pca length weight headroom trunk displacement mat Ev = e(Ev) local J = colsof(Ev) gen eigenvalue = Ev[1, _n] in 1/`J' gen eigen_prop = strofreal(eigenvalue/`J', "%03.2f") in 1/`J' gen PC = _n in 1/`J' gen Cumulative = sum(eigenvalue) in 1/`J' capture set scheme stcolor if _rc { set scheme s1color local stretch ysc(r(. `J'.2)) } local colour1 = cond(c(version) >= 18, "stc1", "blue") local colour2 = cond(c(version) >= 18, "stc2", "red") * mylabels is from Stata Journal * mylabels 0.2(0.2)0.8, myscale(`J' * @) format(%02.1f) local(yla) foreach y in 0.2 0.4 0.6 0.8 { local Y = `J' * `y' local yla `yla' `Y' "`y'" } gen Cumulative_show = strofreal(Cumulative/`J', "%03.2f") list eigenvalue eigen_prop Cumulative PC in 1/`J' screeplot , recast(bar) mla(eigen_prop) mlabpos(12) barw(0.8) lcol(`colour1') fcol(`colour1'*0.2) /// addplot( /// connected Cumulative PC, mla(Cumulative_show) mlabc(`colour2') mlabpos(12) /// ) /// legend(pos(12) row(1)) yaxis(1 2) /// yla(`yla' 0 `J' "1", ang(h) axis(2) labcolor(`colour2')) /// yla(, ang(h) axis(1) labcolor(`colour1')) /// ytitle(Cumulative Proportion, axis(2) color(`colour2')) /// ytitle(Eigenvalues, axis(1) color(`colour1')) xtitle(PC) `stretch'
Comment