Announcement

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

  • Lab position using filter (if)

    Hi all,

    I wondering if its possible use lab position using 2 diferents filter, example:

    Code:
    clear all
    set more off
    sysuse auto
    collapse mpg, by(rep78)
    drop if missing(rep78)
    
    scatter  mpg rep78, ///
    c(l) sort ///
    mlabel(mpg) ///
    mlabposition(6)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	10.2 KB
ID:	1526689


    My goal its use filters to lab position, do you know if its possible?, example:

    Code:
    scatter  mpg rep78, ///
    c(l) sort ///
    mlabel(mpg) ///
    mlabposition(12 if rep78> 2) ///
    mlabposition(6 if rep78< 2)
    Thanks in advance.
    Rodrigo

  • #2
    You can use the -mlabvposition()- option to specify the position for each point:

    Code:
    sysuse auto,clear
    collapse mpg, by(rep78)
    drop if missing(rep78)
    gen pos = 12 if rep > 2
    replace pos = 6 if rep <=2
    
    scatter  mpg rep78, ///
        c(l) sort mlabel(mpg) mlabv(pos)

    Comment


    • #3
      Thanks Scott Merryman for you reply!

      Regards

      Comment


      • #4
        In the same side:

        I am trying to alternate position label (pos=6 and pos=12) in the graph, for this purpose I am trying to generate sequential dicotomic variable.

        For this purpose I am using labvposition package.

        Code example:

        Code:
        sysuse auto,clear
        collapse mpg, by(rep78)
        drop if missing(rep78)
        gen pos = 6
        replace pos = 12 if pos in 1/1
        replace pos = 12 if pos in 3/3
        replace pos = 12 if pos in 5/5
        
        scatter  mpg rep78, ///
            c(l) sort mlabel(mpg) mlabv(pos)
        Click image for larger version

Name:	Sin título.png
Views:	1
Size:	3.9 KB
ID:	1526716


        Do you know other way to generate sequential dcotomic variable?
        Thanks in advance

        Comment


        • #5
          Code:
          egen pos = fill(12 6 12)

          Comment


          • #6
            Code:
            gen pos = cond(mod(_n, 2), 12, 6)

            Comment


            • #7
              Thanks Nick Cox and Scott Merryman , both command works fine!

              Regards.

              Comment

              Working...
              X