Announcement

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

  • Scatter of a local

    Hi, is it not possible to create a scatter of a local variable? I'm evaluating the difference in the probabilities of Y btn men and women for a range of other variables. Through some loops I get a list of that, but when trying to plot it, I can't. Is not possible to make a scatter of a local?

    This code is working (with it I get the mentioned list):

    quietly {

    logit pmvotegrp lrself male retnat income age edulevel

    local maleA=0
    local incomeA=3
    local lrselfA=5
    local edulevelA=3
    local retnatA=3

    local maleB=1
    local incomeB=3
    local lrselfB=5
    local edulevelB=3
    local retnatB=3

    capture drop predA
    capture drop predB

    foreach nn of numlist 1/100 {

    local ageA=`nn'
    local ageB=`nn'


    # delimit ;
    local sysA=_b[_cons]+
    _b[lrself]*`lrselfA'+
    _b[male]*`maleA'+
    _b[retnat]*`retnatA'+
    _b[income]*`incomeA'+
    _b[age]*`ageA'+
    _b[edulevel]*`edulevelA';

    local sysB=_b[_cons]+
    _b[lrself]*`lrselfB'+
    _b[male]*`maleB'+
    _b[retnat]*`retnatB'+
    _b[income]*`incomeB'+
    _b[age]*`ageB'+
    _b[edulevel]*`edulevelB';

    local predA=exp(`sysA')/(1+exp(`sysA'));
    local predB=exp(`sysB')/(1+exp(`sysB'));

    # delimit cr

    local diffBA=`predB'-`predA'

    noisily: display in r "Case `nn' (Age `ageB'): `diffBA' "

    }
    }

    When changing the noisily part for what follows, I get nothing:

    noisily: twoway scatter `diffBA' age, msize(small) mcolor(red)
    , name(dd_age, replace) legend(off)
    title("Probability of voting PM's party, diff btn men and women", size(vsmall))
    xtitle("Age") ytitle("Diff prob men and women")
    nodraw
    xlabel(0(1)100,grid angle(45) labsize(vsmall))
    ylabel(1(0.001)1,grid labsize(vsmall))

    Even if just coding scatter `diffBA' age, I get nothing. Any advice?

  • #2
    scatter wants to see a variable name in the position where you have put diffBA. If I understand your code correctly -- and your code example isn't reproducible -- diffBA will at best contain a numeric constant, so that won't work.

    You seem to be asking for 100 graphs....

    I think this is an example of the XY problem -- http://xyproblem.info/ -- and that you are re-creating what Stata will do for you willing and concisely, perhaps through predict and/or margins and marginsplot.

    Comment

    Working...
    X