Announcement

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

  • marker label values in twoway mata

    Hi
    When I run the code
    Code:
    sysuse auto, clear
    summarize price
    mata:
        mean = st_numscalar("r(mean)")
        sd = st_numscalar("r(sd)")
        p = st_data(., "price")
        R = st_nobs()
        plot_m = sort( (p, (1::R)), 1), mean :+ sd :* invnormal( (1::R) :/ (R+1))
        m = plot_m[., (1,3)]
        mlbl = plot_m[., 2]
    end
    twoway (scatter matamatrix(m)) (function y=x, range(price)) , legend(off)
    I get a nice (Q-Q) graph


    Click image for larger version

Name:	qq.png
Views:	1
Size:	34.1 KB
ID:	1510568
    However, I would like to add marker labels in the scatter plot.
    But I can't. I've tried eg.
    Code:
    . twoway (scatter matamatrix(m), mlabel(matamatrix(mlbl))) (function y=x, range(price)) , legend(off)
    option mlabels() not allowed
    r(198);
    Is there a way of getting marker labels onto the scatter points?
    Kind regards

    nhb

  • #2
    This seems to be a start at what you want.
    Code:
    sysuse auto, clear
    summarize price
    mata:
        mean = st_numscalar("r(mean)")
        sd = st_numscalar("r(sd)")
        p = st_data(., "price")
        R = st_nobs()
        plot_m = sort( (p, (1::R)), 1), mean :+ sd :* invnormal( (1::R) :/ (R+1))
    end
    getmata (y mlbl x) = plot_m
    twoway (scatter y x, mlabels(mlbl)) (function y=x, range(price)) , legend(off)
    Click image for larger version

Name:	labelled.png
Views:	1
Size:	96.0 KB
ID:	1510599

    Comment


    • #3
      William Lisowski Thank you very much.
      I'd forgot -putmatrix-, so this is a very nice solution

      Although I had hoped I would have been able to use matamatrix
      Kind regards

      nhb

      Comment


      • #4
        Niels Henrik Bruun You came close, farther than I would have. Since the output of help twoway scatter suggests that the arguments are variable names and yet you were able to successfully pass it a matrix that it interpreted correctly, I'd say you exploited an undocumented feature that I'll keep in mind for future reference. But apparently your luck ran out at the mlabels() option, which reacted unfavorably to a matrix name as an argument and issue the sort of error message we often see when Stata encounters something it never imagined it would.

        Comment

        Working...
        X