Skip to content

asjadnaqvi/stata-trimap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StataMin issues license Stars version release

Installation | Syntax | Examples | Feedback | Change log


trimap_banner


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 (coming soon):

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

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

The following packages are required to run this command:

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:

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:

graph set window fontface "Arial Narrow"

Syntax

The syntax for the latest version is as follows:

        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 (updated once a new version is submitted)

Examples

Data setup

Get the shapefiles

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

Get the data files

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:

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:

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:

ternary y99prop y15prop y64prop, points 

Test the command

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

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

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

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

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

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

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) 

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)

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)	

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

merge 1:1 NUTS_ID using NUTS3_gva
drop if _m==2
drop _m
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) 

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) 

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

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) 

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 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.