-
-
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
6610f5a
commit a047ecf
Showing
15 changed files
with
111 additions
and
72 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
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,4 +1,4 @@ | ||
v 1.4 | ||
v 1.5 | ||
d STREAMPLOT: A package for creating streamplots in Stata | ||
d | ||
d Asjad Naqvi, | ||
|
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.4 (08 Nov 2022) | ||
*! streamplot v1.5 (20 Nov 2022) | ||
*! Asjad Naqvi ([email protected]) | ||
|
||
* v1.5 (20 Nov 2022): recenter option added. improved variable precision. | ||
* v1.4 (08 Nov 2022): Major code cleanup and some parts reworked. Observation checks. Palette options. label controls. | ||
* v1.3 (20 Jun 2022). Add marker labels and format options | ||
* v1.2 14 Jun 2022: passthru optimizations. error checks. reduce the default smoothing. labels fix | ||
|
@@ -28,7 +29,7 @@ version 15 | |
[ LColor(string) LWidth(string) labcond(string) ] /// | ||
[ YLABSize(string) YLABel(varname) YLABColor(string) offset(real 0.12) droplow ] /// | ||
[ xlabel(passthru) xtitle(passthru) title(passthru) subtitle(passthru) note(passthru) scheme(passthru) name(passthru) xsize(passthru) ysize(passthru) ] /// | ||
[ PERCENT FORMAT(string) ] | ||
[ PERCENT FORMAT(string) RECenter(string) ] | ||
|
||
|
||
|
||
|
@@ -128,13 +129,6 @@ preserve | |
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// prepare the dataset | ||
collapse (sum) `yvar' if `touse', by(`xvar' `by') | ||
|
||
xtset `by' `xvar' | ||
|
@@ -148,22 +142,23 @@ preserve | |
tssmooth ma ``yvar'_ma7' = `yvar' , w(`smooth' 1 0) | ||
|
||
// add the range variable on the x-axis | ||
summ `xvar' if ``yvar'_ma7' != . | ||
local xrmin = r(min) | ||
local xrmax = r(max) + ((r(max) - r(min)) * `offset') | ||
summ `xvar' if ``yvar'_ma7' != ., meanonly | ||
|
||
local xrmin = r(min) | ||
local xrmax = r(max) + ((r(max) - r(min)) * `offset') | ||
|
||
cap drop stack_`yvar' | ||
*cap drop stack_`yvar' | ||
|
||
gen stack_`yvar' = . | ||
gen double stack_`yvar' = . | ||
|
||
sort `xvar' `by' | ||
qui levelsof `xvar', local(lvls) | ||
levelsof `xvar', local(lvls) | ||
|
||
foreach y of local lvls { | ||
|
||
qui summ `by' | ||
qui replace stack_`yvar' = ``yvar'_ma7' if `xvar'==`y' & `by'==r(min) | ||
qui replace stack_`yvar' = ``yvar'_ma7' + stack_`yvar'[_n-1] if `xvar'==`y' & `by'!=r(min) | ||
summ `by', meanonly | ||
replace stack_`yvar' = ``yvar'_ma7' if `xvar'==`y' & `by'==r(min) | ||
replace stack_`yvar' = ``yvar'_ma7' + stack_`yvar'[_n-1] if `xvar'==`y' & `by'!=r(min) | ||
|
||
} | ||
|
||
|
@@ -183,56 +178,66 @@ preserve | |
foreach x of local idlabels { | ||
local idlab_`x' : label `mylab' `x' // store the corresponding value label in a macro | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
reshape wide stack_`yvar' `yvar' , i(`xvar') j(`by') | ||
reshape wide stack_`yvar' `yvar' , i(`xvar') j(`by') | ||
|
||
|
||
foreach x of local idlabels { // here we know how many variables we have | ||
foreach x of local idlabels { // here we know how many variables we have | ||
|
||
lab var stack_`yvar'`x' "`idlab_`x''" | ||
lab var `yvar'`x' "`idlab_`x''" | ||
} | ||
lab var stack_`yvar'`x' "`idlab_`x''" | ||
lab var `yvar'`x' "`idlab_`x''" | ||
} | ||
|
||
|
||
|
||
gen stack_`yvar'0 = 0 // we need this for area graphs | ||
|
||
ds `yvar'* | ||
local items : word count `r(varlist)' | ||
local items = `items' - 1 | ||
|
||
gen meanval_`yvar' = stack_`yvar'`items' / 2 | ||
|
||
ds `yvar'* | ||
local items : word count `r(varlist)' | ||
local items = `items' - 1 | ||
|
||
if "`recenter'" == "" | "`recenter'"=="middle" | "`recenter'"=="mid" | "`recenter'"=="m" { | ||
gen double meanval_`yvar' = stack_`yvar'`items' / 2 | ||
} | ||
|
||
if "`recenter'" == "bottom" | "`recenter'"=="bot" | "`recenter'"=="b" { | ||
gen meanval_`yvar' = 0 | ||
} | ||
|
||
if "`recenter'" == "top" | "`recenter'"=="t" { | ||
local items2 = `items' + 1 | ||
gen double meanval_`yvar' = stack_`yvar'`items2' | ||
} | ||
|
||
|
||
foreach x of varlist stack_`yvar'* { | ||
gen `x'_norm = `x' - meanval_`yvar' | ||
} | ||
foreach x of varlist stack_`yvar'* { | ||
gen double `x'_norm = `x' - meanval_`yvar' | ||
} | ||
|
||
drop meanval* | ||
drop meanval* | ||
|
||
|
||
// this part is for the mid points | ||
// 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) | ||
|
||
|
||
ds stack_`yvar'*norm | ||
local items : word count `r(varlist)' | ||
local items = `items' - 2 | ||
ds stack_`yvar'*norm | ||
local items : word count `r(varlist)' | ||
local items = `items' - 2 | ||
|
||
|
||
|
||
forval i = 0/`items' { | ||
local i0 = `i' | ||
local i1 = `i' + 1 | ||
forval i = 0/`items' { | ||
local i0 = `i' | ||
local i1 = `i' + 1 | ||
|
||
gen y`yvar'`i1' = (stack_`yvar'`i0'_norm + stack_`yvar'`i1'_norm) / 2 if last==1 | ||
} | ||
gen double y`yvar'`i1' = (stack_`yvar'`i0'_norm + stack_`yvar'`i1'_norm) / 2 if last==1 | ||
} | ||
|
||
|
||
|
||
|
@@ -281,7 +286,7 @@ drop lastsum* | |
if "`lwidth'" == "" local lwidth 0.05 | ||
if "`ylabcolor'" != "palette" local ycolor `ylabcolor' | ||
if "`palette'" == "" { | ||
local palette CET C1 | ||
local palette tableau | ||
} | ||
else { | ||
tokenize "`palette'", p(",") | ||
|
@@ -291,11 +296,27 @@ drop lastsum* | |
|
||
|
||
|
||
summ stack_`yvar'0_norm | ||
local ymin = -1 * abs(r(min)) * 1.05 | ||
local ymax = abs(r(min)) * 1.05 | ||
summ stack_`yvar'0_norm, meanonly | ||
|
||
if "`recenter'" == "" | "`recenter'" == "middle" | "`recenter'" == "mid" | "`recenter'" == "m" { | ||
|
||
local ymin = -1 * abs(r(min)) * 1.05 | ||
local ymax = abs(r(min)) * 1.05 | ||
} | ||
|
||
if "`recenter'" == "bottom" | "`recenter'" == "bot" | "`recenter'" == "b" { | ||
|
||
local ymin = 0 | ||
local ymax = abs(r(min)) * 1.05 | ||
} | ||
|
||
if "`recenter'" == "top" | "`recenter'" == "t" { | ||
|
||
local ymin = -1 * abs(r(min)) * 1.05 | ||
local ymax = 0 | ||
} | ||
|
||
|
||
ds stack_`yvar'*norm | ||
local items : word count `r(varlist)' | ||
local items = `items' - 2 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{smcl} | ||
{* 08Nov2022}{...} | ||
{* 20Nov2022}{...} | ||
{hi:help streamplot}{...} | ||
{right:{browse "https://github.com/asjadnaqvi/stata-streamplot":streamplot v1.4 (GitHub)}} | ||
{right:{browse "https://github.com/asjadnaqvi/stata-streamplot":streamplot v1.5 (GitHub)}} | ||
|
||
{hline} | ||
|
||
|
@@ -16,13 +16,10 @@ The command is based on the following guide on Medium: {browse "https://medium.c | |
|
||
{cmd:streamplot} {it:y x} {ifin}, {cmd:by}(varname) {cmd:[} {cmd:palette}({it:str}) {cmd:smooth}({it:num}) {cmd:labcond}({it:str}) {cmd:offset}({it:num}) {cmd:alpha}({it:num}) {cmd:droplow} | ||
{cmdab:lc:olor}({it:str}) {cmdab:lw:idth}({it:str}) {cmdab:ylabs:ize}({it:num}) {cmdab:ylabc:olor}({it:color}|{it:palette}) {cmd:percent} {cmd:format}({it:str}) | ||
{cmd:xlabel}({it:str}) {cmd:xtitle}({it:str}) {cmd:ytitle}({it:str}) {cmd:title}({it:str}) {cmd:subtitle}({it:str}) {cmd:note}({it:str}) | ||
{cmd:xlabel}({it:str}) {cmd:xtitle}({it:str}) {cmd:ytitle}({it:str}) {cmd:title}({it:str}) {cmd:subtitle}({it:str}) {cmd:note}({it:str}) {cmdab:rec:enter}({it:mid|top|bot}) | ||
{cmd:ysize}({it:num}) {cmd:xsize}({it:num}) {cmd:scheme}({it:str}) {cmd:name}({it:str}) {cmd:]} | ||
|
||
|
||
|
||
|
||
|
||
{p 4 4 2} | ||
The options are described as follows: | ||
|
||
|
@@ -37,14 +34,17 @@ The options are described as follows: | |
{p2coldent : {opt droplow}}If there are fewer than 10 observations per {bf:by()} variable, the command will give an error. If only some groups have this issue, then use the {opt droplow} option to drop these observations. | ||
If all groups have few observations, then {cmd:streamplot} cannot be used.{p_end} | ||
|
||
{p2coldent : {opt palette(str)}}Color name is any named scheme defined in the {stata help colorpalette:colorpalette} package. | ||
Default is {stata colorpalette CET C1:{it:CET C1}}.{p_end} | ||
|
||
{p2coldent : {opt smooth(num)}}The smoothing parameter defined in terms of last observations to use. The default value is {it:3}. | ||
A value of 0 implies no smoothing.{p_end} | ||
|
||
{p2coldent : {opt palette(str)}}Color name is any named scheme defined in the {stata help colorpalette:colorpalette} package. | ||
Default is {stata colorpalette tableau:{it:tableau}}.{p_end} | ||
|
||
{p2coldent : {opt alpha(num)}}The transparency of area fills. The default value is {it:100}.{p_end} | ||
|
||
{p2coldent : {opt rec:enter(options)}}This option changes where the graph is recentered. The default option is {opt rec:enter(middle)}. Additional options are {opt rec:enter(top)} or {opt rec:enter(bottom)}. | ||
For brevity, the following can be specified: {it:middle} = {it:mid} = {it:m}, {it:top} = {it:t}, {it:bottom} = {it:bot} = {it:b}.{p_end} | ||
|
||
{p2coldent : {opt offset(num)}}Extends the x-axis range to accommodate labels. The default value is {it:0.12} or 12% of {it:xmax-xmin}.{p_end} | ||
|
||
{p2coldent : {opt ylabc:olor(str)}}Either takes on a named Stata color, e.g. {it:ylabc(red)} for red labels. | ||
|
@@ -87,7 +87,7 @@ Even if you have these installed, it is highly recommended to check for updates: | |
|
||
{title:Examples} | ||
|
||
See {browse "https://github.com/asjadnaqvi/streamplot":GitHub}. | ||
See {browse "https://github.com/asjadnaqvi/stata-streamplot":GitHub}. | ||
|
||
{hline} | ||
|
||
|
@@ -98,10 +98,10 @@ Marc Kaulisch has suggested several useful features across various versions. | |
|
||
{title:Package details} | ||
|
||
Version : {bf:streamplot} v1.4 | ||
This release : 08 Nov 2022 | ||
Version : {bf:streamplot} v1.6 | ||
This release : 20 Nov 2022 | ||
First release: 06 Aug 2021 | ||
Repository : {browse "https://github.com/asjadnaqvi/streamplot":GitHub} | ||
Repository : {browse "https://github.com/asjadnaqvi/stata-streamplot":GitHub} | ||
Keywords : Stata, graph, stream plot | ||
License : {browse "https://opensource.org/licenses/MIT":MIT} | ||
|
||
|
@@ -110,7 +110,6 @@ E-mail : [email protected] | |
Twitter : {browse "https://twitter.com/AsjadNaqvi":@AsjadNaqvi} | ||
|
||
|
||
|
||
{title:References} | ||
|
||
{p 4 8 2}Jann, B. (2018). {browse "https://www.stata-journal.com/article.html?article=gr0075":Color palettes for Stata graphics}. The Stata Journal 18(4): 765-785. | ||
|