and now we will learn how to make a two-way line graph in stata a two-way line graph is appropriate
when measuring or comparing two or more continuous variables and it is just like we learned in school
one of the variables we believe is independent and change it by itself and we would measure
that one going across the horizontal or x axis then the variable that we believe is dependent
upon the first variable is usually measured vertically going up and down the y-axis and
when you plot each corresponding value from your independent variable compared to your dependent
variable you get a line that shows how what the change in one will affect the change in the other
here's the code the red is the command type in to a line to tell theta a line graph is what's
following then leave a space then type the name of the dependent variable and then type the name of
the independent variable now in our example with this simple data set this is exactly what we're
going to type in two-way line is the command to tell theta we want a line graph then snacks will
be our dependent variable and age will be our independent variable what we are measuring is
how many snacks people buy as a result of their age or you could ask the question as a person
get older do they tend to spend more money on snacks at the pool so let's type this in two-way
line and then let's go back here to remind ourselves snacks which is that we assume as
the dependent variable and age which is the independent variable hit enter now here's
the line graph that showed as one gets older they tend to spend more on snacks and more specifically
people who are 12 years old spend about fourteen dollars on snacks people who are ten years old
tend to spend a little more than ten dollars on snacks and people who are 16 years old tend to
spend about twenty dollars on snacks and so on let's take a look at a second example this is
the code how about we compare how age affects the enjoyment level of a person who goes to the
pool so we type in two-way line and what was the code here enjoyment age enjoy men space age and
this is what it looks like it seems that on a scale of enjoyment from one to five people who
are ten years old tend to only enjoy the pool at a level of two whereas people who are 14
years old tend to enjoy it about twice as much now you may well ask can you have more than one
dependent variable in the same graph in other words can more than one variable be dependent
on age and can you put them together in the same picture the answer is yes and this is what the
code looks like you type in the same command to a line type in the name of each of the variables
that you believe are dependent on the very last one the independent variable so in this example
let's take both of the two previous example and put them together in the same line graph
here is the command then enjoyment and snacks and we're going to see one line that measures
how enjoyment changes for age and in the same picture we're going to measure how snacks also
change or how dependent snacks are as it relates to age so let's go ahead and type that in two-way
line enjoy mint snack age and that's how you would type it in take a look at this graph it's
showing you that age is what's coming across here and that the brownish line is measuring
how enjoyment changes for enjoyment changes as age changes and then this blue line actually
the brown line is measuring how much they spend on snacks as they get older and this this blue
line is measuring how much more they enjoy it as the respondents get older and you can have
several dependent variables in one line graph but only one independent variable in the line graph
you can add titles to your x and y access for more clarity for the people looking at the graph this
would be the code it would be the same code that you typed in before then you would put a
comma then add the text second green X title open parentheses quotes words that go across the bottom
close quote parentheses then another space y title open parentheses quote words that go down the side
close quote close parentheses the example we will do is if we're doing to a line for snacks and age
x title should be age of respondent and why title should be hung you know the words spent on neck
now I've copied these these that exact text and now I'm pasting it into the command line if you
copy and paste them into the command line you have to look carefully at little anomalies for example
the beginning quotation marks here are missing for some reason when I could copy and paste so
I'm just going to put those quotes here again make sure to way begins with a lowercase letter
almost all commands in stata or lowercase so now it should work and when i hit enter there's the
line graph and notice it says age of respondents and it says spend on snacks in fact you can even
add a label to the y axis for scale now all you have to do is take the same code that you
typed in a minute ago and add this bit of code next to it you don't even have to put a comma
the only comment goes after the independent variable type it in just like this so in our
example we will type in the command to a line the dependent and canon variable then a comma then we
will type in exactly this text in green for the titles of the x and y axis then after a space
type in exactly this and this will tell stata the bottom measurement is 0 the middle measurement of
the y axis will be 15 and this time the highest measurement will be 30 now i already have copied
this to my clipboard so i'm going to paste it and if you paste again you have to double check
that everything tastes it properly if you like you can pause the video and make sure you type
in your line of code exactly like this as it reflects the four different parts of the code
for the four different things we need in our graph when we hit enter here it is age of respondent and
money spent on snacks looks just like this but you can see along the y-axis that this line starts at
approximately 10 and finishes at approximately 20 because of the scale that we changed in the y-axis