Announcement

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

  • Issues with line graph

    Hi! I am trying to create a line graph, but I am not sure why the line trend has so many sharp ups and downs. While none of the y axis values are below three (absolutely no zeros), the graph shows like there are zeros in my dataset. I expected my graph looks something like the red line (I drew by hand to demonstrate), but am not sure what is causing this. Please see my graph and code below. Many thanks for your help in advance!


    levelsof name, local(levels)
    levelsof type, local(levels2)

    local vars main_variable day_number

    foreach o in `levels' {
    foreach x in `levels2' {
    line `vars' if name==`o' ///
    , xlabel(2(4)82) ytitle("Visit (#)") xtitle("Day number") ///
    title("`: lab (name) `o''" (`: lab (type) `x''))

    }
    }
    Attached Files

  • #2
    The code you show isn't logical. You have nested loops on levels of name and type, but the -line- command only conditions on name. I think your -if- condition is wrong and you meant something like -if name == `o' & type == `x'- Consequently, you are actually replicating the exact same graph for each value of name as many times as there are values of type. And I think this is the cause your problem: you have multiple observations of main_variable for each value of day_number being plotted, and the vertical lines you see are connecting them. Try fixing the -if- condition and I think it will work out correctly.

    As an aside, unless you save, store, or export the graphs, you will just be overwriting each graph with the next one, and in the end you will have only the final one.

    Comment


    • #3
      You were so right, Clyde! Your solution fixed the problem. Thank you so very much for your help!

      Comment

      Working...
      X