Announcement

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

  • How to create a line graph of categorical variable (x-axis) against observations?

    Hi,

    How do I create a graph with multiple lines of different categorical variables, against the observations for each category.

    For example, I have two variables that are measured on the same scale; FathOcc and MothOcc and I want to create a line graph with two lines representing each variable and its plotted against the number of observations. So like if category 1 has 1000 obs for FathOcc and 3000 for MothOcc it will plot it with observations on y-axis and the cat variables on x axis.

    Any help would be appreciated greatly.

  • #2
    Code:
    clear
    set seed 04042022
    set obs 5
    gen cat=_n
    gen obs= runiformint(0, 3000)
    expand 2, g(which)
    replace obs = 2000+ obs if which
    *START HERE
    xtset which cat
    xtline obs, overlay scheme(s1mono) plot2opts(lp(dash)) ///
    leg(order(1 "Fath OCC" 2 "Moth OCC")) ytitle(No. of observations) ///
    xtitle("Category")
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	23.3 KB
ID:	1657892

    Comment

    Working...
    X