-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfeec83
commit d77805a
Showing
25 changed files
with
148 additions
and
91 deletions.
There are no files selected for viewing
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
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*! streamplot v1.7 (01 Apr 2024) | ||
*! streamplot v1.8 (25 Apr 2024) | ||
*! Asjad Naqvi ([email protected]) | ||
|
||
* v1.8 (25 Apr 2024): added labscale option. Added percent/share as substitutes. more flexible for generic options. | ||
* v1.7 (01 Apr 2024): trendline, yline, drop if by() is missing | ||
* v1.61 (15 Jan 2024): fixed wrong locals. changed ylab to just lab. | ||
* v1.6 (15 Oct 2023): cat() option added. yrev, labcond() fixed. major code cleanup. | ||
|
@@ -21,14 +22,12 @@ program streamplot, sortpreserve | |
version 15 | ||
|
||
syntax varlist(min=2 max=2 numeric) [if] [in], by(varname) /// | ||
[ palette(string) alpha(real 100) smooth(real 3) ] /// | ||
[ LColor(string) LWidth(string) labcond(real 0) ] /// | ||
[ LABSize(string) LABColor(string) offset(real 15) ] /// | ||
[ xlabel(passthru) xtitle(passthru) title(passthru) subtitle(passthru) note(passthru) scheme(passthru) name(passthru) xsize(passthru) ysize(passthru) ] /// | ||
[ PERCENT FORMAT(string) RECenter(string) ] /// | ||
[ aspect(passthru) saving(passthru) NOLABel nodraw xscale(passthru) graphregion(passthru) ] /// v1.5x | ||
[ palette(string) alpha(real 100) smooth(real 3) LColor(string) LWidth(string) labcond(real 0) ] /// | ||
[ LABSize(string) LABColor(string) offset(real 15) format(string) RECenter(string) ] /// | ||
[ NOLABel nodraw ] /// v1.5x | ||
[ cat(varname) YREVerse ] /// // v1.6 | ||
[ tline TLColor(string) TLWidth(string) TLPattern(string) droplow yline(passthru) ] // v1.7 | ||
[ tline TLColor(string) TLWidth(string) TLPattern(string) droplow ] /// // v1.7 | ||
[ * labprop labscale(real 0.3333) percent share ] // 1.8 options | ||
|
||
|
||
// check dependencies | ||
|
@@ -54,16 +53,13 @@ version 15 | |
} | ||
} | ||
|
||
if `"`format'"' == "" local format "%12.0fc" | ||
|
||
|
||
|
||
qui { | ||
preserve | ||
|
||
keep if `touse' | ||
|
||
|
||
cap confirm numeric var `by' | ||
if !_rc { | ||
drop if `by'==. | ||
|
@@ -285,63 +281,66 @@ preserve | |
|
||
// this part is for the mid points | ||
|
||
summ `xvar' | ||
gen last = 1 if `xvar'==r(max) | ||
*summ `xvar' | ||
*gen last = 1 if `xvar'==r(max) | ||
|
||
gen double _ylab = . | ||
gen double _yval = . | ||
gen double _yshare = . | ||
gen _yname = "" | ||
|
||
ds _stack*_norm | ||
local items : word count `r(varlist)' | ||
local items = `items' - 2 | ||
|
||
|
||
local counter = 1 | ||
|
||
forval i = 0/`items' { | ||
local i0 = `i' | ||
local i1 = `i' + 1 | ||
|
||
gen double _ylab`i1' = (_stack`i0'_norm + _stack`i1'_norm) / 2 if last==1 | ||
local t : var lab _ma`i1' | ||
|
||
replace _ylab = (_stack`i0'_norm[_N] + _stack`i1'_norm[_N]) / 2 in `counter' | ||
|
||
replace _yval = _yvar`i1'[_N] in `counter' | ||
|
||
replace _yname = "`t'" in `counter' | ||
|
||
local ++counter | ||
} | ||
|
||
egen double _lastsum = rowtotal(_ma*) if last==1 | ||
|
||
|
||
foreach x of varlist _ma* { | ||
gen double `x'_share = (`x' / _lastsum) * 100 | ||
} | ||
|
||
drop _lastsum | ||
|
||
sum _yval, meanonly | ||
replace _yshare = (_yval / `r(sum)') * 100 | ||
|
||
summ `xvar', meanonly | ||
gen _xlab = r(max) if _yval!=. | ||
|
||
**** automate this part | ||
|
||
|
||
ds _stack*norm | ||
local items : word count `r(varlist)' | ||
local items = `items' - 1 | ||
|
||
foreach x of numlist 1/`items' { | ||
|
||
if `"`percent'"' != "" { | ||
local ylabvalues `"string(_ma`x'_share, `"`format'"') + "%""' | ||
|
||
local labvar _ma`x'_share | ||
|
||
} | ||
else { | ||
local ylabvalues `"string(_yvar`x', `"`format'"')"' | ||
|
||
local labvar _yvar`x' | ||
} | ||
|
||
|
||
|
||
local t : var lab _ma`x' | ||
gen _label`x' = "`t'" + " (" + `ylabvalues' + ")" if last==1 & `labvar' >= `labcond' | ||
|
||
} | ||
|
||
|
||
if "`format'" == "" { | ||
if "`percent'"=="" & "`share'"=="" { | ||
local format %15.0fc | ||
} | ||
else { | ||
local format %6.1f | ||
} | ||
} | ||
|
||
|
||
if "`percent'" != "" | "`share'"!="" { | ||
gen _label = _yname + " (" + string(_yshare, "`format'") + "%)" if _yval!=. | ||
} | ||
else { | ||
gen _label = _yname + " (" + string(_yval, "`format'") + ")" if _yval!=. //if last==1 & `labvar' >= `labcond' | ||
} | ||
|
||
|
||
if "`labsize'" == "" local labsize 1.6 | ||
if "`lcolor'" == "" local lcolor white | ||
|
@@ -358,7 +357,7 @@ preserve | |
|
||
|
||
|
||
summ _stack0_norm, meanonly | ||
summ _stack0_norm, meanonly | ||
|
||
if "`recenter'" == "" | "`recenter'" == "middle" | "`recenter'" == "mid" | "`recenter'" == "m" { | ||
|
||
|
@@ -397,51 +396,74 @@ summ _stack0_norm, meanonly | |
local trendline (line _linevar `xvar', lc(`tlcolor') lw(`tlwidth') lp(`tlpattern')) | ||
} | ||
|
||
|
||
|
||
if "`nolabel'"=="" & "`labprop'" == "" & "`labcolor'" =="" { | ||
local labels `labels' (scatter _ylab _xlab if _yval >= `labcond' , mlabel(_label) mcolor(none) mlabsize(`labsize') mlabcolor("`labcolor'")) | ||
} | ||
|
||
|
||
summ _yval, meanonly | ||
local height = r(max) | ||
|
||
|
||
ds _stack*norm | ||
local items : word count `r(varlist)' | ||
local items = `items' - 2 | ||
|
||
|
||
local counter = 1 | ||
|
||
forval x = 0/`items' { | ||
|
||
local numcolor = `items' + 1 | ||
local numcolor = `items' + 1 | ||
|
||
colorpalette `palette', n(`numcolor') nograph `poptions' | ||
colorpalette `palette', n(`numcolor') nograph `poptions' | ||
|
||
local x0 = `x' | ||
local x1 = `x' + 1 | ||
|
||
local areagraph `areagraph' rarea _stack`x0'_norm _stack`x1'_norm `xvar', fcolor("`r(p`x1')'") fi(100) lcolor(`lcolor') lwidth(`lwidth') || | ||
|
||
|
||
if "`labcolor'" == "palette" { | ||
local ycolor "`r(p`x1')'" | ||
} | ||
|
||
|
||
if "`nolabel'"=="" { | ||
local labels `labels' (scatter _ylab`x1' `xvar' if last==1, mlabel(_label`x1') mcolor(none) mlabsize(`labsize') mlabcolor("`ycolor'")) || | ||
if "`labprop'" != "" { | ||
summ _yval in `counter' , meanonly | ||
local labwgt = `labsize' * (r(max) / `height')^`labscale' | ||
|
||
local labels `labels' (scatter _ylab _xlab in `counter' if _yval >= `labcond' , mlabel(_label) mcolor(none) mlabsize(`labwgt') mlabcolor("`ycolor'")) | ||
local ++counter | ||
} | ||
|
||
} | ||
|
||
if "`labprop'"=="" & "`labcolor'"=="palette" { | ||
|
||
local labels `labels' (scatter _ylab _xlab in `counter' if _yval >= `labcond', mlabel(_label) mcolor(none) mlabsize(`labsize') mlabcolor("`ycolor'")) | ||
local ++counter | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
*** final graph | ||
|
||
twoway /// | ||
`areagraph' /// | ||
`labels' /// // (linei 0 date, lc(gs10) lp(dash)) /// | ||
`labels' /// | ||
`trendline' /// | ||
, /// | ||
legend(off) /// | ||
yscale(noline) /// | ||
ytitle("") `xtitle' /// | ||
ylabel(`ymin' `ymax', nolabels noticks nogrid) /// | ||
`xlabel' xscale(noline range(`xrmin' `xrmax')) `yline' /// | ||
`title' `subtitle' `note' `scheme' `xsize' `ysize' `name' `aspect' `saving' `nodraw' `xscale' `graphregion' | ||
|
||
|
||
xscale(noline range(`xrmin' `xrmax')) /// | ||
`options' | ||
|
||
*/ | ||
|
||
restore | ||
|
@@ -454,3 +476,9 @@ end | |
********************************* | ||
******** END OF PROGRAM ********* | ||
********************************* | ||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.