Announcement

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

  • Coefplot. color

    Dear Senior stata user,

    Using coefplot

    Code:
    clear
    input str10 var float X
    "Age"     .6410156    
    "Gender"      0.2905445    
    "Job"      -.1932313    
    "Test"     -.3568878    
    end
    
    order var X
    gsort +X
    mkmat X, mat(X) rownames(var)
    mat X= X'
    
    coefplot (matrix(X))
    Using above, code, how to apply a different color or marker shape in those with negative X value. For instance, if a create an indicator variable with value 1 for those whose X value is negative, how can i show that in the final plot by coloring or shaping the circle symbol in the plot differently
    Appreciate your help

    Ashraf
    Last edited by ashraf abugroun; 10 Feb 2023, 23:24.

  • #2
    I attempted this solution
    Code:
    gen Y = 0 
    replace Y =1 if X < 0
    
    order var X 
    mkmat X if Y ==1, mat(X) rownames(var) 
    mkmat X if Y == 0, mat(Y) rownames(var) 
    mat X= X'
    mat Y= Y'
    
    coefplot (matrix(X)) (matrix(Y))
    However, when having 2 matrices, then results on final coefplot wont be sorted from high to low or vice versa. Wonder if there is another way. Like labeling based on group variable or so.

    Comment


    • #3
      coefplot is from SSC, as you are asked to explain (FAQ Advice #12).

      Code:
      clear
      input str10 var float X
      "Age"     .6410156    
      "Gender"      0.2905445    
      "Job"      -.1932313    
      "Test"     -.3568878    
      end
      
      order var X
      gsort +X
      mkmat X, mat(X) rownames(var)
      mat X= X'
      set scheme s1color
      coefplot (matrix(X), keep(Test Job) mc(blue) msy(s)) (matrix(X), keep(Gender Age) mc(red)), nokey 
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	13.8 KB
ID:	1701171

      Comment

      Working...
      X