Announcement

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

  • Graph Issue - Chart is not populating appropriately

    I am using Stata version 15.1 and I have 47 variables and 1,010 observations in my dataset. I am doing educational research with 112 colleges included (This is setup as a panel data set).

    I am having an issue populating a graph twoway for my data. When I run it the final result looks like the picture below:


    Click image for larger version

Name:	2022-12-22 18_37_01-.png
Views:	1
Size:	42.3 KB
ID:	1694610


    This is the code I am running:

    graph twoway (scatter total_stu_less_than_30000 year, connect(direct) msymbol(circle) msize(large) mcolor(green) yaxis(1) ytitle("Students Enrolled", axis(1))) ///
    ///
    (scatter net_price_less_than_30000 year, connect(direct) msymbol(diamond) msize(small) mcolor(black) yaxis(2) ytitle("Average Discount $", axis(2))), ///
    ///
    xtitle("Year") xlabel(34(1)46, grid) title("Student Enrollment and Discount by Income Category") legend(label(1 "< 30,000") label(2 "< 30,000"))
    Below is a data ex output with the two variables I want to graph included:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long unitid int year double(total_stu_less_than_30000 net_price_less_than_30000)
    101189 2008  53 14455
    101189 2009  55 18647
    101189 2010  49 18399
    101189 2011  78 17140
    101189 2012 110 18130
    101189 2013  83 19247
    101189 2014 155 23712
    101189 2015  96 19835
    101189 2016  97 24862
    105899 2008  16 13586
    105899 2009  16 12350
    105899 2010  10 24830
    105899 2011  28 21553
    105899 2012  12 22665
    105899 2013  17 25219
    105899 2014  27 26093
    105899 2015  32 22058
    105899 2016  19 23151
    107044 2008  89  8302
    107044 2009 103 11113
    107044 2010 112 10992
    107044 2011 142 11525
    107044 2012 127 20056
    107044 2013 120 12960
    107044 2014  91 11825
    107044 2015  96 12338
    107044 2016 109 13442
    107141 2008  33 14331
    107141 2009  47 13682
    107141 2010  66 12624
    107141 2011  52 11807
    107141 2012  42 13333
    107141 2013  42 15351
    107141 2014  47 15310
    107141 2015  44 13921
    107141 2016  37 18018
    109785 2008  72 18025
    109785 2009 122 27147
    109785 2010 176 19738
    109785 2011 180 22018
    109785 2012 174 23732
    109785 2013 165 26717
    109785 2014 155 21479
    109785 2015 165 22258
    109785 2016 163 23574
    110097 2008 117 22356
    110097 2009 173 24204
    110097 2010 142 22389
    110097 2011 138 24125
    110097 2012 123 25538
    110097 2013 119 25064
    110097 2014 148 25382
    110097 2015 122 24595
    110097 2016 108 24981
    110361 2008  69 17595
    110361 2009  85 22773
    110361 2010 173 20323
    110361 2011 192 20303
    110361 2012 210 20886
    110361 2013 226 22748
    110361 2014 240 25711
    110361 2015 240 24115
    110361 2016 189 26628
    112075 2008  42 21477
    112075 2009  32 19398
    112075 2010  55 16972
    112075 2011  42 19496
    112075 2012  42 19329
    112075 2013  54 21191
    112075 2014  59 21798
    112075 2015  64 20332
    112075 2016  50 19675
    112084 2008   8 29101
    112084 2009   6 24378
    112084 2010  11 20602
    112084 2011  19 25326
    112084 2012  31 26494
    112084 2013  27 26812
    112084 2014  21 24011
    112084 2015  18 28841
    112084 2016  22 27328
    114813 2008  24 12726
    114813 2009 128 12596
    114813 2010  64 11915
    114813 2011  48 10727
    114813 2012  68 12391
    114813 2013  56 17174
    114813 2014  52 13714
    114813 2015  26 10811
    114813 2016  59 15178
    117104 2008   8 16466
    117104 2009  12 16728
    117104 2010  12 17063
    117104 2011  22 14564
    117104 2012  22 15666
    117104 2013  17 16930
    117104 2014  29 14498
    117104 2015  25 16583
    117104 2016  17 18121
    120537 2008  15 15294
    end
    label values unitid unitiddf
    label values year yeardf
    label values total_stu_less_than_30000 number_of_studentsdf
    label values net_price_less_than_30000 net_pricedf
    I am most grateful for any assistance with this as I work to graph my data.

  • #2
    You are plotting against year with values in recent years but also asking for xlabel(34/46). Hence there is one cluster of text on the x axis but otherwise your data are plotted against the years. I think the issue is that you don't want what you're asking for. What do 34 to 46 mean here?

    EDIT:

    The graph makes more sense with the option call omitted, but is still a tangled mess because different units are over-plotted and you need to insist on c(L).

    Here today is already tomorrow and so no more from me for the predictable future.
    Last edited by Nick Cox; 22 Dec 2022, 17:04.

    Comment


    • #3
      Nick Cox you hit the nail on the head. When I removed the label and collapsed my data set to one institution to then utilize the average data attached to the record it all resolved. You are much appreciated!

      Comment

      Working...
      X