Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • margins at min and max values of variable

    Hello everyone,

    I would like to use -marginsplot- multiple times. My aim is to plot all values of a continuous variable (here z_v2x_clphy) over dichotomous values (i.v2x_regime_01). I don't want to copy+paste the min and max values of the variable manually like I did here:

    Code:
    fracreg logit dvfrac_year c.z_v2x_clphy##i.v2x_regime_01 [fweight=cnt_total_year], vce(cluster country_id)
    margins i.v2x_regime_01, at(c.z_v2x_clphy=(-2.453303(0.1)1.03632))
    marginsplot
    -summarize- stores r(min) and r(max) values of a variable. Is there a way to use these in the margins syntax? I get "invalid numlist" error message as I type:
    Code:
    sum z_v2x_clphy
    margins i.v2x_regime_01, at(c.z_v2x_clphy=(r(min)(0.1)r(max)))
    Please let me know if you I shall provide some further information. I am open to alternatives and work arounds.

    Have a good one!
    Pavel
    Last edited by Pavel Satra; 26 Apr 2019, 10:08.

  • #2
    What you tried is very close to correct: you just need some local macro dereferencing:

    Code:
    sum z_v2x_clphy
    margins i.v2x_regime_01, at(c.z_v2x_clphy=(`r(min)' (0.1) `r(max)'))
    Do remember that this code will break if you insert any commands between -sum- and -margins- that return anything in r(). So you might want to save r(min) and r(max) in named local macros and use those instead if you are uncertain how your code will evolve over time.

    Comment


    • #3
      Dear Clyde, thank you very much for your detailled and helpful answer. The named local macros are indeed relevant for my scenario!

      Comment

      Working...
      X