mhamjediers / nopo_decomposition

Stata ado files to run matching-based decompositions
MIT License
3 stars 0 forks source link

Post-command for graph of matching-contribution across another variable #4

Closed mhamjediers closed 11 months ago

mhamjediers commented 1 year ago

Similar to the occupation-graph in our submission

maximilian-sprengholz commented 1 year ago

Open for testing as nopo dadb varname

maximilian-sprengholz commented 1 year ago

Regarding the plotoptions, I suggest that we just return the default contents so that users can post the full set with their adjustments (similar to the kmatch_cmdline).

mhamjediers commented 1 year ago

Looks good; I'll check how many standard-options can be implemented maybe more directly and for the rest we follow your suggestion

maximilian-sprengholz commented 1 year ago

Bug: Scale centering does not always work, which is a problem with multiple xscales. Only happens with by(). Seems to be Stata bug. I have tested several hacks to no avail.

Carlas example:

run "nopo.ado"
use "GPG_exampledata.dta", clear

nopo decomp pensionbeZero_tc duration_CIV duration_CW spell_CW_age_1 AFtransition__CIV_RET_  AFtransition__FT_RET_, by(frau)
tempfile temp
nopo dadb duration_CW, save(`temp') keepalllevels
use `temp', clear
sum pensionbeZero_tc_diff
local _mmax = abs(r(min)) * 1.75
sum pensionbeZero_tc_diff_weighted
local _wmmax = abs(r(min)) * 1.75
gen nx = `_mmax'

local plotbyreleveled "duration_CW"
replace pensionbeZero_tc_diff_weighted = 1.75 * pensionbeZero_tc_diff_weighted
gen mirror2 = -pensionbeZero_tc_diff_weighted

// plot
twoway ///
    (bar pensionbeZero_tc_diff `plotbyreleveled', horizontal xaxis(2)) ///
    (scatter `plotbyreleveled' pensionbeZero_tc_diff_weighted, xaxis(1) xscale(noreverse)) ///
    (scatter `plotbyreleveled' mirror2, xaxis(1)) ///
    , by(frau)
maximilian-sprengholz commented 1 year ago
maximilian-sprengholz commented 11 months ago

I have implemented only xsize and ysize as direct options for the plot. These should allow to resolve most scaling issues. Everything else is determined by defaults and returned in r(). Users can then either:

  1. adjust these returns and feed them back to the plot command via, e.g. twopts
  2. build their own plot from saved data and these returns

We could allow for many more direct options, but I think that in the end, you'll always need more than we offer, and in this case the two options allow for maximum flexibility (to be sure, the second option involves some coding and is not just copy paste).

Closing.