From 592f0ab2ed10dc69a7b936acb919369303f45b81 Mon Sep 17 00:00:00 2001 From: Asjad Naqvi Date: Mon, 15 Jan 2024 22:00:29 +0100 Subject: [PATCH] v1.71 --- CITATION.cff | 4 ++-- LICENSE | 2 +- README.md | 9 ++++++--- installation/sankey.ado | 38 +++++++++++++++++++++++++++++++++----- installation/sankey.pkg | 6 +++--- installation/sankey.sthlp | 9 +++++---- installation/stata.toc | 4 ++-- 7 files changed, 52 insertions(+), 20 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 5c20a6b..25524bc 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,6 +3,6 @@ authors: - family-names: "Naqvi" given-names: "Asjad" title: "Stata package ``sankey''" -version: 1.7 -date-released: 2023-11-06 +version: 1.71 +date-released: 2024-01-15 url: "https://github.com/asjadnaqvi/stata-sankey" \ No newline at end of file diff --git a/LICENSE b/LICENSE index fb09ad3..78c18d4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Asjad Naqvi +Copyright (c) 2024 Asjad Naqvi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ba7ae0e..aeec131 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ --- -# sankey v1.7 -(06 Nov 2023) +# sankey v1.71 +(15 Jan 2024) This package allows users to draw Sankey plots in Stata. It is based on the [Sankey Guide](https://medium.com/the-stata-guide/stata-graphs-sankey-diagram-ecddd112aca1) published on [the Stata Guide](https://medium.com/the-stata-guide) on Medium on October 2021. @@ -25,7 +25,7 @@ SSC (**v1.7**): ssc install sankey, replace ``` -GitHub (**v1.7**): +GitHub (**v1.71**): ``` net install sankey, from("https://raw.githubusercontent.com/asjadnaqvi/stata-sankey/main/installation/") replace @@ -427,6 +427,9 @@ Please open an [issue](https://github.com/asjadnaqvi/stata-sankey/issues) to rep ## Change log +**v1.71 (15 Jan 2024)** +- Fixed a bug where numerical `from()` and `to()` variables with value labels were messing up the labels in the final figure (reported by Ian White). + **v1.7 (06 Nov 2023)** - Fixed `valcond()` dropping bar values. - Fixed `ctitles()` getting random colors. It now defaults to black. diff --git a/installation/sankey.ado b/installation/sankey.ado index ac3babd..6ea02db 100644 --- a/installation/sankey.ado +++ b/installation/sankey.ado @@ -1,7 +1,8 @@ -*! sankey v1.7 (06 Nov 2023) +*! sankey v1.71 (15 Jan 2024) *! Asjad Naqvi (asjadnaqvi@gmail.com) -*v1.7 (06 Nov 2023): fix valcond() dropping labels in bars, added percent (still in beta), add ctitlepos() option. minor cleanups +*v1.71 (15 Jan 2024): fixed a bug where value labels of to() and from() were overwriting each other. +*v1.7 (06 Nov 2023): fix valcond() dropping labels in bars, added percent (still in beta), added ctpos() option. minor cleanups *v1.61 (22 Jul 2023): Adding saving() option. minor fixes *v1.6 (11 Jun 2023): Major rewrite of the core routines. Labels added. twp sorts added. Program is faster. *v1.52 (29 May 2023): Add option where wwn flows are considered stock @@ -43,7 +44,7 @@ version 15 // check dependencies cap findfile colorpalette.ado if _rc != 0 { - display as error "The palettes package is missing. Install the {stata ssc install palettes, replace:palettes} and {stata ssc install colrspace, replace:colrspace} packages." + display as error "The {bf:palettes} package is missing. Install the {stata ssc install palettes, replace:palettes} and {stata ssc install colrspace, replace:colrspace} packages." exit } @@ -122,10 +123,31 @@ preserve keep `varlist' `from' `to' `by' clrlvl + // convert value labels to strings + cap confirm numeric var `from' + if _rc==0 { + if "`: value label `from''" != "" { + decode `from', gen(temp1) + drop `from' + ren temp1 `from' + } + } + + cap confirm numeric var `to' + if _rc==0 { + if "`: value label `to''" != "" { + decode `to', gen(temp2) + drop `to' + ren temp2 `to' + } + } + + collapse (sum) `varlist' (mean) clrlvl , by(`from' `to' `by') gen markme = . + if "`stock'" != "" { replace markme = `from'== `to' } @@ -165,6 +187,8 @@ preserve reshape long var val, i(id layer xcut) j(marker) + + // variable type check if substr("`: type var'",1,3) != "str" { @@ -181,6 +205,7 @@ preserve } + gen layer2 = layer replace layer2 = layer2 + 1 if marker==2 @@ -258,7 +283,8 @@ preserve gen double y2 = heightsum - + + *** add gap tempvar mygap @@ -306,6 +332,8 @@ preserve } + + gsort layer2 marker var markme `ssort2' // this determines the second sort by layer2 marker var: gen double stack_end = sum(val) if markme!=1 @@ -359,7 +387,7 @@ preserve } } - + gen stack_x = layer2 diff --git a/installation/sankey.pkg b/installation/sankey.pkg index a8daa36..15986c3 100644 --- a/installation/sankey.pkg +++ b/installation/sankey.pkg @@ -1,4 +1,4 @@ -v 1.7 +v 1.71 d {bf:SANKEY}: A Stata package for sankey plots. d See {bf:help sankey} after installation. d @@ -8,9 +8,9 @@ d KW: Stata d KW: graphs d KW: sankey d -d Distribution-Date: 20231106 +d Distribution-Date: 20240115 d -d This version: 06 Nov 2023 +d This version: 15 Jan 2024 d First version: 08 Dec 2022 d License: MIT d diff --git a/installation/sankey.sthlp b/installation/sankey.sthlp index 63c82c4..c3be6d7 100644 --- a/installation/sankey.sthlp +++ b/installation/sankey.sthlp @@ -1,7 +1,7 @@ {smcl} -{* 06Nov2023}{...} +{* 15Jan2024}{...} {hi:help sankey}{...} -{right:{browse "https://github.com/asjadnaqvi/stata-sankey":sankey v1.7 (GitHub)}} +{right:{browse "https://github.com/asjadnaqvi/stata-sankey":sankey v1.71 (GitHub)}} {hline} @@ -168,6 +168,7 @@ See {browse "https://github.com/asjadnaqvi/stata-sankey":GitHub} for examples. {title:Version history} +- {bf:1.71} : Fixed a bug where from() and to() value labels were overwriting each other. - {bf:1.7} : Fixed {opt valcond()} dropping bar values, and fixed ctitles color to black. Added {opt percent} (beta), {opt ctpos()}. - {bf:1.61} : Adding saving() option. - {bf:1.6} : Rewrite of core routines. {opt sortby()} split into {opt sort1()} and {opt sort2()}. New option {opt stock} added. @@ -183,8 +184,8 @@ See {browse "https://github.com/asjadnaqvi/stata-sankey":GitHub} for examples. {title:Package details} -Version : {bf:sankey} v1.7 -This release : 06 Nov 2023 +Version : {bf:sankey} v1.71 +This release : 15 Jan 2024 First release: 08 Dec 2022 Repository : {browse "https://github.com/asjadnaqvi/stata-sankey":GitHub} Keywords : Stata, graph, sankey diff --git a/installation/stata.toc b/installation/stata.toc index 61badde..ddc4be9 100644 --- a/installation/stata.toc +++ b/installation/stata.toc @@ -1,7 +1,7 @@ -v 1.7 +v 1.71 d 'SANKEY': A Stata package for Sankey plots d -d Distribution-Date: 20231106 +d Distribution-Date: 20240115 d d Asjad Naqvi d asjadnaqvi@gmail.com