An open API service indexing awesome lists of open source software.

https://github.com/asjadnaqvi/stata-trimap

A Stata package for tri-variate maps
https://github.com/asjadnaqvi/stata-trimap

ado package stata ternary trimap trivariate

Last synced: 6 months ago
JSON representation

A Stata package for tri-variate maps

Awesome Lists containing this project

README

          

![StataMin](https://img.shields.io/badge/stata-2015-blue) ![issues](https://img.shields.io/github/issues/asjadnaqvi/stata-trimap) ![license](https://img.shields.io/github/license/asjadnaqvi/stata-trimap) ![Stars](https://img.shields.io/github/stars/asjadnaqvi/stata-trimap) ![version](https://img.shields.io/github/v/release/asjadnaqvi/stata-trimap) ![release](https://img.shields.io/github/release-date/asjadnaqvi/stata-trimap)

[Installation](#Installation) | [Syntax](#Syntax) | [Examples](#Examples) | [Feedback](#Feedback) | [Change log](#Change-log)

---

![trimap_banner](https://github.com/user-attachments/assets/a06e7bc6-3e2e-4356-adf1-48aadd511d3a)

---

# trimap v1.1
(12 Sep 2024)

This package provides the ability to draw trimaps Stata.

## Installation

The package can be installed via SSC or GitHub. The GitHub version, *might* be more recent due to bug fixes, feature updates etc, and *may* contain syntax improvements and changes in *default* values. See version numbers below. Eventually the GitHub version is published on SSC.

The SSC version (**v1.0**):

```stata
ssc install trimap, replace
```

Or it can be installed from GitHub (**v1.1**):

```stata
net install trimap, from("https://raw.githubusercontent.com/asjadnaqvi/stata-trimap/main/installation/") replace
```

The following packages are required to run this command:

```stata
ssc install geoplot, replace
ssc install ternary, replace
ssc install palettes, replace
ssc install colrspace, replace
ssc install moremata, replace
```

Even if you have the package installed, make sure that it is updated `ado update, update`.

If you want to make a clean figure, then it is advisable to load a clean scheme. These are several available and I personally use the following:

```stata
ssc install schemepack, replace
set scheme white_tableau
```

You can also push the scheme directly into the graph using the `scheme(schemename)` option. See the help file for details or the example below.

I also prefer narrow fonts in figures with long labels. You can change this as follows:

```stata
graph set window fontface "Arial Narrow"
```

## Syntax

The syntax for the latest version is as follows:

```stata
trimap varL varR varB [if] [in],
[ frame(frame name) cuts(num) normalize(1|100) geo(layers) geopost(options) zoom fill
points lines labels colorL(str) colorR(str) colorB(str) lwidth(str) msize(str) malpha(num) mcolor(str) mlcolor(str)
mlwidth(str) leglwidth(str) leglcolor(str) mlabel(var) mlabsize(str) mlabcolor(str) mlabposition(str) xscale(num) yscale(num) * ]
```

See the help file `help trimap` for details.

The most basic use is as follows:

```
trimap varL varR varB, frame(framename)
```

representing left, right and bottom variables respectively. The framename is the frame in which the data is stored.

## Citation guidelines
Software packages take countless hours of programming, testing, and bug fixing. If you use this package, then a citation would be highly appreciated. Suggested citations:

*in BibTeX*

```
@software{trimap,
author = {Naqvi, Asjad},
title = {Stata package ``trimap''},
url = {https://github.com/asjadnaqvi/stata-trimap},
version = {1.1},
date = {2024-09-12}
}
```

*or simple text*

```
Naqvi, A. (2024). Stata package "trimap" version 1.1. Release date 12 September 2024. https://github.com/asjadnaqvi/stata-trimap.
```

*or see [SSC citation](XXXX) (updated once a new version is submitted)*

## Examples

### Data setup

Get the shapefiles

```stata
foreach x in NUTS0 NUTS0_shp NUTS1 NUTS1_shp NUTS2 NUTS2_shp NUTS3 NUTS3_shp {
copy "https://github.com/asjadnaqvi/stata-trimap/raw/main/data/`x'.dta" "`x'.dta", replace
}
```

Get the data files

```stata
foreach x in NUTS3_pop NUTS3_gva NUTS2_edu NUTS2_tourstay {
copy "https://github.com/asjadnaqvi/stata-trimap/raw/main/data/`x'.dta" "`x'.dta", replace
}
```

Set up the data:

```stata
geoframe create nuts0, replace
geoframe create nuts1, replace
geoframe create nuts2, replace
geoframe create nuts3, replace
```

```
frames change nuts3

merge 1:1 NUTS_ID using NUTS3_pop
drop if _m==2
drop _m

format *prop %5.0f
```

Test if `geoplot` is working correctly:

```stata
geoplot ///
(area nuts3 y15prop, cuts(0(10)100) ) ///
(line nuts0, lc(white) lw(0.2)) ///
, tight title("Population share 15-64")


geoplot ///
(area nuts3 y64prop, cuts(0(10)100) ) ///
(line nuts0, lc(white) lw(0.2)) ///
, tight title("Population share 0-14")


geoplot ///
(area nuts3 y99prop, cuts(0(10)100) ) ///
(line nuts0, lc(white) lw(0.2)) ///
, tight title("Population share 65+")
```

which gives us:


```stata
ternary y99prop y15prop y64prop, points
```

### Test the command

```stata
trimap y99prop y15prop y64prop, frame(nuts3) mlc(white)
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) mlc(white) ///
geo( (line nuts0, lc(white) lw(0.05)) )
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom mlc(white) cuts(4) ///
geo( (line nuts0, lc(white) lw(0.05)) ) norm(1)
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom mlc(white) cuts(4) ///
geo( (line nuts0, lc(white) lw(0.05)) )
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom cuts(4) mlc(white) ///
geo((line nuts0, lc(white) lw(0.05)))
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom cuts(4) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) )
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom cuts(4) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msym(point)
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom cuts(4) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msize(0.5) mcolor(white%50) leglc(black) mlc(white)
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom cuts(2) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msize(0.5) mcolor(white%60) leglc(black) mlc(white)
```

```stata
trimap y99prop y15prop y64prop, frame(nuts3) zoom cuts(4) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msize(0.5) mcolor(white%60) leglc(black) colorB(#FFFF00) colorL(#F11D8C) colorR(#01A0C6) mlc(white)
```

### Try another layer

```stata
merge 1:1 NUTS_ID using NUTS3_gva
drop if _m==2
drop _m
```

```stata
trimap gva_tertiary gva_primary gva_secondary, frame(nuts3) cuts(4) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill colorB(#FFFF00) colorL(#F11D8C) colorR(#01A0C6) msize(0.3) mcolor(black%60) mlc(none)
```

```stata
trimap gva_secondary gva_tertiary gva_primary , frame(nuts3) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill colorB(#FFFF00) colorL(#F11D8C) colorR(#01A0C6) msize(0.3) mcolor(black%60) mlc(none)
```

```stata
trimap gva_secondary gva_tertiary gva_primary , frame(nuts3) cuts(8) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill colorB(#FFFF00) colorL(#F11D8C) colorR(#01A0C6) msize(0.3) mcolor(black%60) mlc(none)
```

### And other layers at the NUTS2 level

```stata
frame change nuts2

merge 1:1 NUTS_ID using NUTS2_edu
drop if _m==2
drop _m

trimap edu_primary edu_secondary edu_tertiary, frame(nuts2) cuts(2) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msize(0.4) mcolor(black%60) mlc(none)
```

```
trimap edu_primary edu_secondary edu_tertiary, frame(nuts2) zoom cuts(2) ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msize(0.4) mcolor(black%60) mlc(none)
```

```stata
merge 1:1 NUTS_ID using NUTS2_tourstay.dta
drop if _m==2
drop _m

trimap tour_hotels tour_other tour_camping , frame(nuts2) cuts(4) zoom ///
geo( (line nuts1, lc(white) lw(0.05)) (line nuts0, lc(white) lw(0.2)) ) ///
fill msize(0.4) mcolor(black%60) mlc(none)
```

## Feedback

Please open an [issue](https://github.com/asjadnaqvi/stata-trimap/issues) to report errors, feature enhancements, and/or other requests.

## Change log

**v1.1 (12 Sep 2024)**
- Package aligned with `ternary` by adding options `norm()`, `mlabel()`, `mlabcolor()`, `mlabposition()`, `mlabsize()`.
- Better `zoom`.
- Minor cleanups.

**v1.0 (28 Aug 2024)**
- First release.