代码拉取完成,页面将自动刷新
同步操作将从 连享会/eda 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
********************************************************************************
* Description of the Program - *
* EDA subroutine used to create heatmap of correlations between continuous *
* variables in the dataset. *
* *
* Program Output - *
* Creates heatmap GPH and PDF as well as entries in the LaTeX document *
* *
* Lines - *
* 157 *
* *
********************************************************************************
*! edaheat
*! v 0.0.2
*! 17jul2018
// Drop program from memory if already loaded
cap prog drop edaheat
// Define program
prog def edaheat, rclass
// Stata version used to interpret syntax
version 14
// Define the syntax structure of the program
syntax varlist(min=2) [if] [in], root(string asis) [ keepgph ]
// Mark observations to use
marksample touse, strok novarlist
// Add section header to LaTeX file
file write doc "\section{Correlations} \newpage\clearpage" _n
// Add subsection header
file write doc "\subsection{Correlations Between Continuous Variables} \newpage\clearpage" _n
// Preserve current state of the data
preserve
// Keep only cases satisfying if/in condition
keep if `touse'
// Keep only the listed variables
keep `varlist'
// Loop over variables to get variable labels
foreach v of var `varlist' {
// Clean the variable label
texclean `"`: var l `v''"'
// Get variable label
loc `v'lab `r(clntex)'
// Check for null strings
if `"``v'lab'"' == "" {
// Clean the variable name
texclean `"`v'"', r
// Assign the variable name to the label macro
loc `v'lab `r(clntex)'
} // End IF Block for null variable label handling
} // Emd Loop to get variable labels
// Get pairwise correlation coefficient estimates
qui: pwcorr `varlist'
// Store the correlation matrix
mat edaheatmat = r(C)
// Assign rownames to matrix
mat rownames edaheatmat = `varlist'
// Assign column names to matrix
mat colnames edaheatmat = `varlist'
// Clear existing data from memory
clear
// Load the correlation matrix as the data
qui: svmat edaheatmat
// Generate an id variable
qui: g xvar = _n
// Store the maximum value of _n
loc maxn = `c(N)'
// Normalize the data
qui: reshape long edaheatmat, i(xvar) j(yvar)
// Loop over ids to assign variable labels
forv i = 1/`maxn' {
// Get the ith word from varlist and use that to get the
la def xvar `i' `"`: word `i' of `varlist'lab'"', modify
} // End Loop to define value labels
// Assign value labels
la val xvar xvar
la val yvar xvar
// Change end of line delimited to semicolon
#d ;
// Create a contour plot for the correlations
cap: qui: tw contour edaheatmat yvar xvar, heatmap xlab(1(1)`maxn', val
labsize(tiny) angle(90)) ylab(1(1)`maxn', val labsize(tiny) angle(0)
nogrid) graphr(ic(white) fc(white) lc(white)) ccut(-1(.2)1) ysca(rev)
ccolor("127 59 8" "179 88 6" "224 130 20" "253 184 99" "254 224 182"
"216 218 235" "178 171 210" "128 115 172");
// This is the one used for inclusion to work around the issues with
// twoway contour
tw contour edaheatmat yvar xvar, heatmap xlab(1(1)`maxn', val
labsize(tiny) angle(90)) ylab(1(1)`maxn', val labsize(tiny) angle(0)
nogrid) graphr(ic(white) fc(white) lc(white)) ccut(-1(.2)1) ysca(rev)
ccolor("127 59 8" "179 88 6" "224 130 20" "253 184 99" "254 224 182"
"247 247 247" "216 218 235" "178 171 210" "128 115 172" "84 39 136"
"45 0 75") xti("Continuous Variables") yti("Continuous Variables")
zti("Estimated" "Correlation Coefficient")
ti("Correlations Between Continuous Variables");
// End of Line delimited to carriage return
#d cr
// Export the graph to pdf
gr export `"`root'/graphs/edaheatmap.pdf"', as(pdf) replace
// Check for keepgph option
if "`keepgph'" != "" {
// If not turned on syntax to delete Stata GPH file
qui: gr save `"`root'/graphs/edaheatmap.gph"', replace
} // End IF Block for gph save definition
// Include in the LaTeX document
file write doc "\begin{figure}[h!]" _n
file write doc `"\caption{Correlation Heatmap \label{fig:heatmap}}"' _n
file write doc `"\includegraphics[width=\textwidth]{edaheatmap.pdf}"' _n
file write doc "\end{figure} \newpage\clearpage" _n
// Return the matrix used for the heat map from the function
ret mat edacorr = edaheatmat
// Restore data to previous state
restore
// End of program definition
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。