From 257476632cec7f0de938e8e47f55f7bcab191423 Mon Sep 17 00:00:00 2001 From: Fernando Rios-Avila Date: Tue, 18 Jun 2024 15:49:34 -0400 Subject: [PATCH] s s --- fra_tools/tabstat2.ado | 13 ++++++--- pieplot/pie_i.ado | 60 ++++++++++++++++++++++++++++++++++++++++++ pieplot/pieplot.ado | 15 +++++++++++ pieplot/pieplot.do | 60 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 pieplot/pie_i.ado create mode 100644 pieplot/pieplot.ado create mode 100644 pieplot/pieplot.do diff --git a/fra_tools/tabstat2.ado b/fra_tools/tabstat2.ado index 5b1dcf7..e0c7357 100644 --- a/fra_tools/tabstat2.ado +++ b/fra_tools/tabstat2.ado @@ -1,17 +1,22 @@ -*! v0.1 alt to tabstat +*! v0.2 Two ways to collect Results +* v0.1 alt to tabstat program tabstat2, rclass syntax anything(everything) [aw iw fw] [if] [in], [save *] tabstat `0' - tempname smatrix + tempname smatrix smatrix2 local j=1 if "`save'"!="" { while _rc==0 { matrix `smatrix' = nullmat(`smatrix'),r(Stat`j') - local j=`j'+1 + matrix `smatrix2' = nullmat(`smatrix2')\r(Stat`j') + + local j=`j'+1 capture confirm matrix r(Stat`j') } } return add return matrix tmatrix = `smatrix' -end \ No newline at end of file + return matrix tmatrix2 = `smatrix2' + +end diff --git a/pieplot/pie_i.ado b/pieplot/pie_i.ado new file mode 100644 index 0000000..b2d59b3 --- /dev/null +++ b/pieplot/pie_i.ado @@ -0,0 +1,60 @@ +capture program drop pie_i +capture program drop re_scale + +program re_scale, rclass + syntax anything, [total] + numlist "`anything'" , min(0) range(>=0) + tempname tval + scalar `tval'=0 + foreach j of numlist `anything' { + scalar `tval'=`tval'+`j' + } + + if `tval'>100 { + foreach j of numlist `anything' { + local newlist `newlist' `=`j'/`tval'*100' + } + } + else if "`total'"!="" { + foreach j of numlist `anything' { + local newlist `newlist' `=`j'/`tval'*100' + } + } + else { + local newlist `anything' `=100-`tval'' + } + return local newlist `newlist' +end + +program pie_i + syntax anything, [total RESolution(int 100) plotopt(string asis) ] + qui:re_scale `anything', `total' + local newlist `r(newlist)' + tempname toplot + frame create `toplot' + frame `toplot': { + set obs `resolution' + range re 2*_pi 0 + local hi0 = 0 + set obs `=`resolution'+1' + foreach i of numlist `newlist' { + local j = `j'+1 + local jm1 = `j'-1 + ** Local Cum + local lw`j'=`hi`jm1'' + local hi`j'=`lw`j''+`i'/100 + qui:gen x`j' = cos(re*`i'/100+`lw`j''*2*_pi) + qui:gen y`j' = sin(re*`i'/100+`lw`j''*2*_pi) + qui:replace x`j'=0 in `=`resolution'+1' + qui:replace y`j'=0 in `=`resolution'+1' + } + local tt `j' + local j =0 + + forvalues i = 1/`tt' { + local pieplot `pieplot' (area x`i' y`i', nodropbase lw(vthin)) + } + + two `pieplot', `plotopt' aspect(1) yscale(off) xscale(off) + } +end \ No newline at end of file diff --git a/pieplot/pieplot.ado b/pieplot/pieplot.ado new file mode 100644 index 0000000..8659ed2 --- /dev/null +++ b/pieplot/pieplot.ado @@ -0,0 +1,15 @@ +capture program drop pie_ii +program pie_ii + syntax anything, [*] + tempname nframe + frame create `nframe' + frame `nframe' { + set obs 1 + foreach i in `anything' { + local j = `j'+1 + gen v`j'=`i' + local vlist `vlist' v`j' + } + graph pie `vlist', `options' + } +end \ No newline at end of file diff --git a/pieplot/pieplot.do b/pieplot/pieplot.do new file mode 100644 index 0000000..2bfa935 --- /dev/null +++ b/pieplot/pieplot.do @@ -0,0 +1,60 @@ +*capture program drop pie_i +*capture program drop re_scale + +program re_scale, rclass + syntax anything, [total] + numlist "`anything'" , min(0) range(>=0) + tempname tval + scalar `tval'=0 + foreach j of numlist `anything' { + scalar `tval'=`tval'+`j' + } + + if `tval'>100 { + foreach j of numlist `anything' { + local newlist `newlist' `=`j'/`tval'*100' + } + } + else if "`total'"!="" { + foreach j of numlist `anything' { + local newlist `newlist' `=`j'/`tval'*100' + } + } + else { + local newlist `anything' `=100-`tval'' + } + return local newlist `newlist' +end + +program pie_i + syntax anything, [total RESolution(int 100) plotopt(string asis) ] + re_scale `anything', `total' + local newlist `r(newlist)' + tempname toplot + frame create `toplot' + frame `toplot': { + set obs `resolution' + range re 2*_pi 0 + local hi0 = 0 + set obs `=`resolution'+1' + foreach i of numlist `newlist' { + local j = `j'+1 + local jm1 = `j'-1 + ** Local Cum + local lw`j'=`hi`jm1'' + local hi`j'=`lw`j''+`i'/100 + gen x`j' = cos(re*`i'/100+`lw`j''*2*_pi) + gen y`j' = sin(re*`i'/100+`lw`j''*2*_pi) + replace x`j'=0 in `=`resolution'+1' + replace y`j'=0 in `=`resolution'+1' + } + local tt `j' + local j =0 + + forvalues i = 1/`tt' { + local pieplot `pieplot' (area x`i' y`i', nodropbase lw(vthin)) + } + + two `pieplot', `plotopt' aspect(1) yscale(off) xscale(off) + } +end \ No newline at end of file