Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
friosavila committed Jun 20, 2024
2 parents 49091ff + 2574766 commit f63f21b
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fra_tools/tabstat2.ado
Original file line number Diff line number Diff line change
@@ -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
return matrix tmatrix2 = `smatrix2'

end
60 changes: 60 additions & 0 deletions pieplot/pie_i.ado
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions pieplot/pieplot.ado
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions pieplot/pieplot.do
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f63f21b

Please sign in to comment.