Announcement

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

  • scatter with dividing vertical line

    Dear Statalist Members,

    I have the log wages data below for States in the the North and Southern part of the USA. I want the North and South scatterplots plotted within their confidence interval in the same plane (side by side) one on the left the other on the right separated by a vertical line. Please assist me with Stata code on how to do this.

    Best,

    Bridget


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int Year double(lwage lower_CI upper_CI) str5 Location
    2002  1.711985  1.706673 1.719326 "North"
    2003  1.737491  1.732496  1.74274 "North"
    2004  1.771409  1.765555 1.775009 "North"
    2005  1.792736  1.791759 1.798001 "North"
    2006   1.82777  1.824415 1.831621 "North"
    2007  1.871802  1.865636 1.872996 "North"
    2008  1.909543  1.905088 1.913832 "North"
    2009  1.908168  1.903264 1.911063 "North"
    2010   1.89762  1.895806 1.902935 "North"
    2011  1.909543  1.905559 1.914572 "North"
    2012  1.926483  1.921635 1.931521 "North"
    2013  1.937831  1.931713 1.941615 "North"
    2014  1.947897   1.94591 1.953028 "North"
    2015  1.974598  1.971443 1.979361 "North"
    2016  2.016828  2.014903  2.02163 "North"
    2017  2.058072  2.054124 2.062057 "North"
    2018  2.079931  2.079442 2.081689 "North"
    2002 1.9097076   1.90879 1.927659 "South"
    2003 1.8709564 1.8698743 1.902333 "South"
    2004  2.335431  2.330566 2.340156 "South"
    2005  2.353275  2.347558 2.359444 "South"
    2006  2.379982  2.374264 2.385404 "South"
    2007  2.422144  2.416161 2.430994 "South"
    2008   2.46805  2.460708 2.473171 "South"
    2009  2.470574  2.465069 2.477289 "South"
    2010  2.460121  2.453588 2.465812 "South"
    2011  2.468101  2.462321 2.474453 "South"
    2012  2.472572  2.465714 2.478218 "South"
    2013   2.48315  2.479687 2.487309 "South"
    2014  2.491621    2.4861 2.499139 "South"
    2015  2.507192  2.501436 2.512333 "South"
    2016  2.523785   2.51824  2.52734 "South"
    2017  2.542393  2.536455 2.547666 "South"
    2018  2.540358  2.533697 2.545926 "South"
    end

  • #2
    Here's what I think you're asking for, more or less, plus something that seems to work better in my view:


    Code:
    scatter lwage Year, ms(Oh) || rcap *_CI Year, yla(1.6(0.2)2.6) by(Location, note("") legend(off)) xla(2002(4)2018, format(%tyY)) 
    
    gen toshow = substr(Location, 1, 1) 
    
    scatter lwage Year, ms(none) mla(toshow) mlabpos(0) xla(2002(4)2018)

    Comment


    • #3
      Thank you so much Nick. You have been a life saver.

      Comment


      • #4
        Sorry to come back on this. What if i want to do the same thing but for individual years?

        clear
        input int Year double(lwage lower_CI upper_CI) str5 Location
        2002 1.711985 1.706673 1.719326 "North"
        2002 1.737491 1.732496 1.74274 "North"
        2002 1.771409 1.765555 1.775009 "North"
        2002 1.792736 1.791759 1.798001 "North"
        2002 1.82777 1.824415 1.831621 "North"
        2002 1.871802 1.865636 1.872996 "North"
        2002 1.909543 1.905088 1.913832 "North"
        2002 1.908168 1.903264 1.911063 "North"
        2002 1.89762 1.895806 1.902935 "North"
        2002 1.909543 1.905559 1.914572 "North"
        2002 1.926483 1.921635 1.931521 "North"
        2002 1.937831 1.931713 1.941615 "North"
        2002 1.947897 1.94591 1.953028 "North"
        2002 1.974598 1.971443 1.979361 "North"
        2002 2.016828 2.014903 2.02163 "North"
        2002 2.058072 2.054124 2.062057 "North"
        2002 2.079931 2.079442 2.081689 "North"
        2002 1.9097076 1.90879 1.927659 "South"
        2002 1.8709564 1.8698743 1.902333 "South"
        2002 2.335431 2.330566 2.340156 "South"
        2002 2.353275 2.347558 2.359444 "South"
        2002 2.379982 2.374264 2.385404 "South"
        2002 2.422144 2.416161 2.430994 "South"
        2002 2.46805 2.460708 2.473171 "South"
        2002 2.470574 2.465069 2.477289 "South"
        2002 2.460121 2.453588 2.465812 "South"
        2002 2.468101 2.462321 2.474453 "South"
        2002 2.472572 2.465714 2.478218 "South"
        2002 2.48315 2.479687 2.487309 "South"
        2002 2.491621 2.4861 2.499139 "South"
        2002 2.507192 2.501436 2.512333 "South"
        2002 2.523785 2.51824 2.52734 "South"
        2002 2.542393 2.536455 2.547666 "South"
        2002 2.540358 2.533697 2.545926 "South"
        end
        [/CODE]


        Best,

        Bridget

        Comment


        • #5
          It is hard to know what you want here. In the absence of state names there seems no reason to treat the order of observations as anything but accidental.

          Does this help? (impute code for confidence intervals too).

          Code:
          bysort Location (lwage) : gen id = _n 
          
          gen toshow = substr(Location, 1, 1)
          
          scatter lwage id, by(Location, note("")) xla(none) xtitle("")
          If you to show state names, you should switch the axes.

          Comment


          • #6
            Nick,

            You are very right. The first code
            scatter lwage Year, ms(Oh) || rcap *_CI Year, yla(1.6(0.2)2.6) by(Location, note("") legend(off)) xla(2002(4)2018, format(%tyY)) does exactly what i need plots the two next to each other. All i need is to use the state names as labels. Sorry for my lack of clarity. I have included the full dataset for names of the states in the north and in the south

            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input int Year double(lwage lower_CI upper_CI) str5 Location str14 State
            2002  1.711985  1.706673 1.719326 "North" "Connecticut"   
            2002  1.737491  1.732496  1.74274 "North" " Illinois"     
            2002  1.771409  1.765555 1.775009 "North" "Iowa"          
            2002  1.792736  1.791759 1.798001 "North" " Indiana"      
            2002   1.82777  1.824415 1.831621 "North" " Maine"        
            2002  1.871802  1.865636 1.872996 "North" "Massachusetts" 
            2002  1.909543  1.905088 1.913832 "North" "Michigan"      
            2002  1.908168  1.903264 1.911063 "North" " Minnesota"    
            2002   1.89762  1.895806 1.902935 "North" " Missouri"     
            2002  1.909543  1.905559 1.914572 "North" "North Dakota" 
            2002  1.926483  1.921635 1.931521 "North" "Ohio"          
            2002  1.937831  1.931713 1.941615 "North" "Pennsylvania"  
            2002  1.947897   1.94591 1.953028 "North" " Nebraska"     
            2002  1.974598  1.971443 1.979361 "North" "New Hampshire" 
            2002  2.016828  2.014903  2.02163 "North" " New Jersey " 
            2002  2.058072  2.054124 2.062057 "North" "New York"      
            2002  2.079931  2.079442 2.081689 "North" "Wisconsin"     
            2002 1.9097076   1.90879 1.927659 "South" " Alabama"     
            2002 1.8709564 1.8698743 1.902333 "South" "Arkansas"      
            2002  2.335431  2.330566 2.340156 "South" "Delaware"      
            2002  2.353275  2.347558 2.359444 "South" "Florida"       
            2002  2.379982  2.374264 2.385404 "South" "Georgia"       
            2002  2.422144  2.416161 2.430994 "South" "Kentucky"      
            2002   2.46805  2.460708 2.473171 "South" "Louisiana"     
            2002  2.470574  2.465069 2.477289 "South" "Maryland"      
            2002  2.460121  2.453588 2.465812 "South" "Mississippi"   
            2002  2.468101  2.462321 2.474453 "South" "North Carolina"
            2002  2.472572  2.465714 2.478218 "South" "Oklahoma"      
            2002   2.48315  2.479687 2.487309 "South" "South Carolina"
            2002  2.491621    2.4861 2.499139 "South" "Tennessee"     
            2002  2.507192  2.501436 2.512333 "South" "Texas"         
            2002  2.523785   2.51824  2.52734 "South" "Virginia "     
            2002  2.542393  2.536455 2.547666 "South" " West Virginia"
            2002  2.540358  2.533697 2.545926 "South" "Arizona"       
            end

            Best,

            Bridget

            Comment


            • #7
              The confidence intervals are so narrow that I struggle to see much point in plotting them. Here is some sample code.

              Meanwhile, wages in West Virginia >> those in Connecticut?? Perhaps you just made up these data, but otherwise the near-coincidence of alphabetical order and order of wages suggests a mix-up earlier.

              Code:
              replace State = trim(State)
              set scheme s1color
              graph dot lwage, over(State, sort(1)) by(Location, note("") col(1)) linetype(line) lines(lcolor(gs8) lw(thin)) ysize(7) exclude0 nofill subtitle(, nobexpand pos(9) nobox fcolor(none))
              Click image for larger version

Name:	bridget.png
Views:	1
Size:	33.7 KB
ID:	1583772

              Last edited by Nick Cox; 28 Nov 2020, 05:28.

              Comment


              • #8
                This is perfect. Thank you very much.

                Truly grateful

                Comment

                Working...
                X