Greetings. I'm working on an .ado file that handles lasagna plots. It relies on the -twoway contour- command and works more or less as expected. Code and example usage are below.
I'd like to distribute as a package, but there are a few things that need to be resolved first. Specifically, when there are many (>25 or so) units represented on the Y axis, I cannot seem to get them spaced so that there is a reasonable amount of vertical padding between them (as seen in the example). Secondly, it would be more appropriate to generate the yId variable as a tempvar. But if I do so, I cannot seem to pass it to -twoway contour- without an error (var does not exist).
Any suggestions are appreciated.
Cheers,
Geoff
I'd like to distribute as a package, but there are a few things that need to be resolved first. Specifically, when there are many (>25 or so) units represented on the Y axis, I cannot seem to get them spaced so that there is a reasonable amount of vertical padding between them (as seen in the example). Secondly, it would be more appropriate to generate the yId variable as a tempvar. But if I do so, I cannot seem to pass it to -twoway contour- without an error (var does not exist).
Any suggestions are appreciated.
Cheers,
Geoff
Code:
capture program drop lasagna program define lasagna syntax varlist(min=3 max=3) [if] [in], label(varname) tokenize `varlist' *number the y values consecutively so that they display evenly on graph cap drop yId egen yId=group(`2') * get a unique list of y values to make labels for each preserve duplicates drop yId, force local max=_N * add the text label for each one to the labels local foreach i of numlist 1/`max' { local labelText=`label'[`i'] local ylab `"`ylab'`i' "`labelText'" "' } * get our original data back and make the graph restore twoway contour `1' yId `3', heatmap levels(5) /// ylabel(`ylab', angle(horizontal) labsize(vsmall) ) cap drop Yid end *use http://www.stata-press.com/data/r15/nlswork.dta, clear *save nlswork, replace use nlswork, clear * keep a reasonable number of years for graphing keep if inrange(year,82,88) * randomly assign each respondent to a state so we can see how the graph labeling works bys idcode: gen fips=runiformint(1, 56) if _n==1 bys idcode: replace fips=fips[1] * generate a longitudinal file by state collapse (mean) ln_wage, by(fips year) * get names for the respondent fips codes statastates, fips(fips) keep if _merge==3 lasagna ln_wage fips year, label(state_name)
Comment