SlideShare a Scribd company logo
1 of 16
Lab 3: Set Working Directory, Scatterplots and Introduction to
Linear Regression
Chao-yo Cheng
[email protected]
Zsuzsanna Magyar
[email protected]
January 16, 2016
1 Section objectives
In this section we will use the HW2.dta. This dataset is a small
set of variables from the larger
“Maddison dataset” 1 By the end, you should be comfortable
using commands to import
your .dta file, making (somewhat) fancy scatterplots, and
running () regressions.
2 Commands
In this lab, you should become familiar with the following
commands.
cd
use
regress
and
twoway scatter
lfit
scheme ()
3 Set working directory and quickly running a .do file
• Log in and open Stata.
• Log in the class website. Save the Homework 2 data in “My
Documents” (or any folder
that works for you).
• Open a .do file. First set the working directory on Stata. Type:
cd "insert path address"
To get the address of your path, right click on “My documents”
and press “Copy address”
so you can copy this inside your “” after cd.
1See here for more information:
http://www.ggdc.net/maddison/maddison-project/home.htm.
1
• To import the data type the command use. Type:
use HW2.dta
• Check whether or not the data has been imported properly.
• Now you know how to open your data using code. This means
you can quickly run your
.do file on a clean dataset using the clear all command at the top
of the .do file.
This will save you the trouble of opening a fresh dataset once
your do file is finished.
• To sum up, at the top of your .do file, type
clear all
cd "path address"
use HW2.dta
Question 1. How many variables are in the dataset, and how
many observations are there?
4 Scatterplots
• Everything after the “,” in a graphical command is an option.
The variables being
graphed come before the comma.
• Sometimes it is nice to use a scheme for your scatterplot so it
looks simpler. Here we
use the scheme (s1mono). Schemes determine the overall look
of a graph.
• To draw scatterplots with observation labels and titles for the
y and x axis. Type
twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)), ///
scheme (s1mono) ///
ytitle("GDP per capita 2000") ///
xtitle("GDP per capita 1500") ///
title("Scatterplot of GDP per capita 1500 versus 2000")
• Add a line of best fit using lfit command. Type:
twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)) (lfit
gdppc_2000 gdppc_
1500, color(blue)), ///
scheme (s1mono) ///
ytitle("GDP per capita 2000") ///
xtitle("GDP per capita 1500") ///
title("Scatterplot of GDP per capita 1500 versus 2000")
Question 2. What relationship does the slope of the fitted line
indicate?
5 Linear regression
• The dependent variable (or outcome variable) is what we are
trying to explain. It is
also called the “outcome” or Y .
2
• The explanatory (or independent variables) are what we use to
do the explaining. These
variables are also called predictors, as we think they are trying
to predict the dependent
variable.
• The command for a regression is regress.
• Now let’s run a regression. Note that your dependent variable
always comes
before the independent variable. You should remember what
units you are working
in in order to help you interpret your results. Type:
regress gdppc_2000 gdppc_1500
Question 3. What is the outcome in this regression? What
variable are we using to predict
the outcome? How do we interpret the coefficient?
6 Summary statistics by continent
• In Homework 1, you calculated the mean for each region by
typing three lines of code.
A quicker way to do this is to use the tabstat command followed
by by.
• Generate a single variable for continent. The straight vertical
line means “or.” Type
gen continent = .
replace continent = 1 if africa == 1
replace continent = 2 if east_asia == 1 | west_asia ==1 |
cent_asia ==1
replace continent = 3 if latin_america ==1
replace continent = 4 if west_europe ==1 | east_europe ==1
replace continent = 5 if country == "United States" | country ==
"Canada"
replace continent = 6 if country == "Australia" | country ==
"New Zealand"
• Lets see what we have.
tab continent
• Now we label the new variable.
label define contname 1 "Africa" 2 "Asia" 3 "Latin America" 4
"Europe" 5 "North
America" 6 "Australia"
label values continent contname
• Suppose we want the mean population for each continent.
tabstat pop_1820, statistics(mean) by(continent)
3
Section objectivesCommandsSet working directory and quickly
running a .do fileScatterplotsLinear regressionSummary
statistics by continent
Lab 3: Set Working Directory, Scatterplots and Introduction to
Linear Regression
Chao-yo Cheng
[email protected]
Zsuzsanna Magyar
[email protected]
January 16, 2016
1 Section objectives
In this section we will use the HW2.dta. This dataset is a small
set of variables from the larger
“Maddison dataset” 1 By the end, you should be comfortable
using commands to import
your .dta file, making (somewhat) fancy scatterplots, and
running () regressions.
2 Commands
In this lab, you should become familiar with the following
commands.
cd
use
regress
and
twoway scatter
lfit
scheme ()
3 Set working directory and quickly running a .do file
• Log in and open Stata.
• Log in the class website. Save the Homework 2 data in “My
Documents” (or any folder
that works for you).
• Open a .do file. First set the working directory on Stata. Type:
cd "insert path address"
To get the address of your path, right click on “My documents”
and press “Copy address”
so you can copy this inside your “” after cd.
1See here for more information:
http://www.ggdc.net/maddison/maddison-project/home.htm.
1
• To import the data type the command use. Type:
use HW2.dta
• Check whether or not the data has been imported properly.
• Now you know how to open your data using code. This means
you can quickly run your
.do file on a clean dataset using the clear all command at the top
of the .do file.
This will save you the trouble of opening a fresh dataset once
your do file is finished.
• To sum up, at the top of your .do file, type
clear all
cd "path address"
use HW2.dta
Question 1. How many variables are in the dataset, and how
many observations are there?
4 Scatterplots
• Everything after the “,” in a graphical command is an option.
The variables being
graphed come before the comma.
• Sometimes it is nice to use a scheme for your scatterplot so it
looks simpler. Here we
use the scheme (s1mono). Schemes determine the overall look
of a graph.
• To draw scatterplots with observation labels and titles for the
y and x axis. Type
twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)), ///
scheme (s1mono) ///
ytitle("GDP per capita 2000") ///
xtitle("GDP per capita 1500") ///
title("Scatterplot of GDP per capita 1500 versus 2000")
• Add a line of best fit using lfit command. Type:
twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)) (lfit
gdppc_2000 gdppc_
1500, color(blue)), ///
scheme (s1mono) ///
ytitle("GDP per capita 2000") ///
xtitle("GDP per capita 1500") ///
title("Scatterplot of GDP per capita 1500 versus 2000")
Question 2. What relationship does the slope of the fitted line
indicate?
5 Linear regression
• The dependent variable (or outcome variable) is what we are
trying to explain. It is
also called the “outcome” or Y .
2
• The explanatory (or independent variables) are what we use to
do the explaining. These
variables are also called predictors, as we think they are trying
to predict the dependent
variable.
• The command for a regression is regress.
• Now let’s run a regression. Note that your dependent variable
always comes
before the independent variable. You should remember what
units you are working
in in order to help you interpret your results. Type:
regress gdppc_2000 gdppc_1500
Question 3. What is the outcome in this regression? What
variable are we using to predict
the outcome? How do we interpret the coefficient?
6 Summary statistics by continent
• In Homework 1, you calculated the mean for each region by
typing three lines of code.
A quicker way to do this is to use the tabstat command followed
by by.
• Generate a single variable for continent. The straight vertical
line means “or.” Type
gen continent = .
replace continent = 1 if africa == 1
replace continent = 2 if east_asia == 1 | west_asia ==1 |
cent_asia ==1
replace continent = 3 if latin_america ==1
replace continent = 4 if west_europe ==1 | east_europe ==1
replace continent = 5 if country == "United States" | country ==
"Canada"
replace continent = 6 if country == "Australia" | country ==
"New Zealand"
• Lets see what we have.
tab continent
• Now we label the new variable.
label define contname 1 "Africa" 2 "Asia" 3 "Latin America" 4
"Europe" 5 "North
America" 6 "Australia"
label values continent contname
• Suppose we want the mean population for each continent.
tabstat pop_1820, statistics(mean) by(continent)
3
Section objectivesCommandsSet working directory and quickly
running a .do fileScatterplotsLinear regressionSummary
statistics by continent
All tables and figures should be numbered and fully titled, e.g.
Figure 1: Histogram of average per capita income, 1975 and
2009.
All work must be concise and presented clearly. Write in
complete and correct English sentences. Do not just give a
number as an answer. Students lose points for unclear or
incomplete presentation of data and findings.
If the person reading and grading your assignment cannot
understand what you are trying to say, they cannot give you full
credit for your ideas.
For full credit, please note which Stata command you used to
obtain each part of the answer to each question
One example how to interpret the slope (beta) coefficient is the
following :
On average, a (unit) increase in X (your independent variable)
will be associated with SLOPE (unit) (increase/decrease) in Y
(your dependent variable).
Please fill in the terms in parentheses and in capital letters.
Of course maybe you learned a slightly different language in
another class and you are welcome to use that language. But do
not forget to use the units of the variables and by all means
include a version of the language "on average..”
do not forget that the intercept (alpha or constant) is the the
average of Y (or the predicted Y) when X is 0.
Furthermore if you are comfortable with it you can provide a
substantive interpretation of the coefficients, you can interpret
the standard errors and the R^2-red.
I know some of you may have forgotten some of this but we
will have a review of the OLS model in this week’s section and
of course you can look through your notes from your intro to
stats classes as well.
The goal of this assignment is to describe the historical growth
of population and income around the world. All tables and
figures should be numbered and titled, e.g. Figure 1: Scatterplot
of GDP per capita in 1500 and 2000.
I. The first set of questions can be answered using the dataset
hw2.dta.
1.Compare the wealth of countries in 1600 to the wealth of
countries in 2001.
Are the wealthy countries in 1600 the same as the wealthy
countries in 2001?
In order to explore this question, first generate and report a
scatter plot by country of gdp per capita in 1600 and gdp per
capita in 2001. [Hint: Label the values on the scatter plot with
country names using the mlabel() option.]
To investigate the strength of the relationship, report a
regression with gdp per capita in 2001 as the dependent variable
and gdp per capita 1600 as the regressor.
Interpret the results.
2. Report the mean gdp per capita in 1820 and 2001 by world
region. [Hint: Use the "tabstat" command with the by() option.]
What is the ratio of western Europe’s per capita gdp to the
global average per capita gdp in 1820? And In 2001?
What is western Europe’s income ratio in those years?
Which regions were the poorest in 1820 and in 2001?
3. Compare the populations of countries in 1600 to their
populations in 2001.
Report a graph and regression that demonstrates the
relationship.
How strong is the relationship? [Hint: You may want to create
new variables that are the logarithms of populations in the two
periods to improve the graphic relationship. The Stata command
log() takes the log of a value.]
4. What is the relationship of population to wealth in 1600?
[Hint: This question is not asking you about the relations to per
capita income.] In 2001?
Generate a graphic and a statistical comparison in both periods
and summarize the comparative relationship. [Hint: For
graphical purposes, you again may want to use logarithmic
values.]
Create a third graph and regression to answer the following
question: Have countries with larger populations in 1600 done
better over the subsequent 401 years than countries which
started with small populations?
II. The final question can be answered using the dataset
korea.dta.
5. Sort the data by year and report a table with the population
and gdp per capita of South and North Korea for the dates that
have data for both countries.
Create a scatter plot using the following command:
twoway (line gdppc year if country=="North Korea",
clcolor(green) clpat(dash) legend(label(1 "North Korea")
label(2 "South Korea"))) (line gdppc year if country=="South
Korea", clcolor(red) clpat(dot) clwidth(medthick))
How would you interpret the data?
What do they say about the importance of government
institutions for economic growth?
What alternative explanations can you think of? [Hint: Korea
was a single country for most of the time period of this data set,
wasoccupied by Japan beginning in 1905, and split into North
(communist) and South(capitalist) at the end of WWII in 1945.
See the CIA factbook for more
information:https://www.cia.gov/library/publications/the-world-
factbook/geos/kn.html.]

More Related Content

Similar to Lab 3 Set Working Directory, Scatterplots and Introduction to.docx

R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfattalurilalitha
 
Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Ashwini Mathur
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionFranck Pachot
 
R programming slides
R  programming slidesR  programming slides
R programming slidesPankaj Saini
 
Rightand wrong[1]
Rightand wrong[1]Rightand wrong[1]
Rightand wrong[1]slange
 
De-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekendsDe-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekendsDSCUSICT
 
Building and deploying analytics
Building and deploying analyticsBuilding and deploying analytics
Building and deploying analyticsCollin Bennett
 
Stata time-series-fall-2011
Stata time-series-fall-2011Stata time-series-fall-2011
Stata time-series-fall-2011Feryanto W K
 
Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015
Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015
Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015Codemotion
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciencesalexstorer
 
Unit I - introduction to r language 2.pptx
Unit I - introduction to r language 2.pptxUnit I - introduction to r language 2.pptx
Unit I - introduction to r language 2.pptxSreeLaya9
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on rAbhik Seal
 
Decision tree induction
Decision tree inductionDecision tree induction
Decision tree inductionthamizh arasi
 

Similar to Lab 3 Set Working Directory, Scatterplots and Introduction to.docx (20)

R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
Data Exploration in R.pptx
Data Exploration in R.pptxData Exploration in R.pptx
Data Exploration in R.pptx
 
Rightand wrong[1]
Rightand wrong[1]Rightand wrong[1]
Rightand wrong[1]
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
De-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekendsDe-Cluttering-ML | TechWeekends
De-Cluttering-ML | TechWeekends
 
How To Diffuse
How To DiffuseHow To Diffuse
How To Diffuse
 
Building and deploying analytics
Building and deploying analyticsBuilding and deploying analytics
Building and deploying analytics
 
Stata time-series-fall-2011
Stata time-series-fall-2011Stata time-series-fall-2011
Stata time-series-fall-2011
 
Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015
Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015
Big Data, a space adventure - Mario Cartia - Codemotion Rome 2015
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
 
Unit I - introduction to r language 2.pptx
Unit I - introduction to r language 2.pptxUnit I - introduction to r language 2.pptx
Unit I - introduction to r language 2.pptx
 
Basic programming
Basic programmingBasic programming
Basic programming
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on r
 
Decision tree induction
Decision tree inductionDecision tree induction
Decision tree induction
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
DAA Notes.pdf
DAA Notes.pdfDAA Notes.pdf
DAA Notes.pdf
 

More from DIPESH30

please write a short essay to address the following questions. Lengt.docx
please write a short essay to address the following questions. Lengt.docxplease write a short essay to address the following questions. Lengt.docx
please write a short essay to address the following questions. Lengt.docxDIPESH30
 
please write a diary entry from the perspective of a French Revoluti.docx
please write a diary entry from the perspective of a French Revoluti.docxplease write a diary entry from the perspective of a French Revoluti.docx
please write a diary entry from the perspective of a French Revoluti.docxDIPESH30
 
Please write the definition for these words and provide .docx
Please write the definition for these words and provide .docxPlease write the definition for these words and provide .docx
Please write the definition for these words and provide .docxDIPESH30
 
Please view the filmThomas A. Edison Father of Invention, A .docx
Please view the filmThomas A. Edison Father of Invention, A .docxPlease view the filmThomas A. Edison Father of Invention, A .docx
Please view the filmThomas A. Edison Father of Invention, A .docxDIPESH30
 
Please watch the clip from the movie The Break Up.  Then reflect w.docx
Please watch the clip from the movie The Break Up.  Then reflect w.docxPlease watch the clip from the movie The Break Up.  Then reflect w.docx
Please watch the clip from the movie The Break Up.  Then reflect w.docxDIPESH30
 
please write a report on Social Media and ERP SystemReport should.docx
please write a report on Social Media and ERP SystemReport should.docxplease write a report on Social Media and ERP SystemReport should.docx
please write a report on Social Media and ERP SystemReport should.docxDIPESH30
 
Please write 200 wordsHow has the healthcare delivery system chang.docx
Please write 200 wordsHow has the healthcare delivery system chang.docxPlease write 200 wordsHow has the healthcare delivery system chang.docx
Please write 200 wordsHow has the healthcare delivery system chang.docxDIPESH30
 
Please view the documentary on Typhoid Mary at httpswww..docx
Please view the documentary on Typhoid Mary at httpswww..docxPlease view the documentary on Typhoid Mary at httpswww..docx
Please view the documentary on Typhoid Mary at httpswww..docxDIPESH30
 
Please use the two attachments posted to complete work.  Detailed in.docx
Please use the two attachments posted to complete work.  Detailed in.docxPlease use the two attachments posted to complete work.  Detailed in.docx
Please use the two attachments posted to complete work.  Detailed in.docxDIPESH30
 
Please use the sources in the outline (see photos)The research.docx
Please use the sources in the outline (see photos)The research.docxPlease use the sources in the outline (see photos)The research.docx
Please use the sources in the outline (see photos)The research.docxDIPESH30
 
Please submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docxPlease submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docxDIPESH30
 
Please think about the various learning activities you engaged in du.docx
Please think about the various learning activities you engaged in du.docxPlease think about the various learning activities you engaged in du.docx
Please think about the various learning activities you engaged in du.docxDIPESH30
 
Please type out the question and answer it underneath. Each question.docx
Please type out the question and answer it underneath. Each question.docxPlease type out the question and answer it underneath. Each question.docx
Please type out the question and answer it underneath. Each question.docxDIPESH30
 
Please use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docxPlease use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docxDIPESH30
 
Please use from these stratagies This homework will be to copyies .docx
Please use from these stratagies This homework will be to copyies .docxPlease use from these stratagies This homework will be to copyies .docx
Please use from these stratagies This homework will be to copyies .docxDIPESH30
 
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docxPLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docxDIPESH30
 
Please share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docxPlease share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docxDIPESH30
 
Please select and answer one of the following topics in a well-org.docx
Please select and answer one of the following topics in a well-org.docxPlease select and answer one of the following topics in a well-org.docx
Please select and answer one of the following topics in a well-org.docxDIPESH30
 
Please see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docxPlease see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docxDIPESH30
 
Please see the attachment and look over the LOOK HERE FIRST file b.docx
Please see the attachment and look over the LOOK HERE FIRST file b.docxPlease see the attachment and look over the LOOK HERE FIRST file b.docx
Please see the attachment and look over the LOOK HERE FIRST file b.docxDIPESH30
 

More from DIPESH30 (20)

please write a short essay to address the following questions. Lengt.docx
please write a short essay to address the following questions. Lengt.docxplease write a short essay to address the following questions. Lengt.docx
please write a short essay to address the following questions. Lengt.docx
 
please write a diary entry from the perspective of a French Revoluti.docx
please write a diary entry from the perspective of a French Revoluti.docxplease write a diary entry from the perspective of a French Revoluti.docx
please write a diary entry from the perspective of a French Revoluti.docx
 
Please write the definition for these words and provide .docx
Please write the definition for these words and provide .docxPlease write the definition for these words and provide .docx
Please write the definition for these words and provide .docx
 
Please view the filmThomas A. Edison Father of Invention, A .docx
Please view the filmThomas A. Edison Father of Invention, A .docxPlease view the filmThomas A. Edison Father of Invention, A .docx
Please view the filmThomas A. Edison Father of Invention, A .docx
 
Please watch the clip from the movie The Break Up.  Then reflect w.docx
Please watch the clip from the movie The Break Up.  Then reflect w.docxPlease watch the clip from the movie The Break Up.  Then reflect w.docx
Please watch the clip from the movie The Break Up.  Then reflect w.docx
 
please write a report on Social Media and ERP SystemReport should.docx
please write a report on Social Media and ERP SystemReport should.docxplease write a report on Social Media and ERP SystemReport should.docx
please write a report on Social Media and ERP SystemReport should.docx
 
Please write 200 wordsHow has the healthcare delivery system chang.docx
Please write 200 wordsHow has the healthcare delivery system chang.docxPlease write 200 wordsHow has the healthcare delivery system chang.docx
Please write 200 wordsHow has the healthcare delivery system chang.docx
 
Please view the documentary on Typhoid Mary at httpswww..docx
Please view the documentary on Typhoid Mary at httpswww..docxPlease view the documentary on Typhoid Mary at httpswww..docx
Please view the documentary on Typhoid Mary at httpswww..docx
 
Please use the two attachments posted to complete work.  Detailed in.docx
Please use the two attachments posted to complete work.  Detailed in.docxPlease use the two attachments posted to complete work.  Detailed in.docx
Please use the two attachments posted to complete work.  Detailed in.docx
 
Please use the sources in the outline (see photos)The research.docx
Please use the sources in the outline (see photos)The research.docxPlease use the sources in the outline (see photos)The research.docx
Please use the sources in the outline (see photos)The research.docx
 
Please submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docxPlease submit a minimum of five (5) detailed and discussion-provokin.docx
Please submit a minimum of five (5) detailed and discussion-provokin.docx
 
Please think about the various learning activities you engaged in du.docx
Please think about the various learning activities you engaged in du.docxPlease think about the various learning activities you engaged in du.docx
Please think about the various learning activities you engaged in du.docx
 
Please type out the question and answer it underneath. Each question.docx
Please type out the question and answer it underneath. Each question.docxPlease type out the question and answer it underneath. Each question.docx
Please type out the question and answer it underneath. Each question.docx
 
Please use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docxPlease use the following technique-Outline the legal issues t.docx
Please use the following technique-Outline the legal issues t.docx
 
Please use from these stratagies This homework will be to copyies .docx
Please use from these stratagies This homework will be to copyies .docxPlease use from these stratagies This homework will be to copyies .docx
Please use from these stratagies This homework will be to copyies .docx
 
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docxPLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
PLEASE THOROUGHLY ANSWER THE FOLLOWING FIVE QUESTIONS BELOW IN.docx
 
Please share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docxPlease share your thoughts about how well your employer, military .docx
Please share your thoughts about how well your employer, military .docx
 
Please select and answer one of the following topics in a well-org.docx
Please select and answer one of the following topics in a well-org.docxPlease select and answer one of the following topics in a well-org.docx
Please select and answer one of the following topics in a well-org.docx
 
Please see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docxPlease see the attachment for the actual work that is require.  This.docx
Please see the attachment for the actual work that is require.  This.docx
 
Please see the attachment and look over the LOOK HERE FIRST file b.docx
Please see the attachment and look over the LOOK HERE FIRST file b.docxPlease see the attachment and look over the LOOK HERE FIRST file b.docx
Please see the attachment and look over the LOOK HERE FIRST file b.docx
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

Lab 3 Set Working Directory, Scatterplots and Introduction to.docx

  • 1. Lab 3: Set Working Directory, Scatterplots and Introduction to Linear Regression Chao-yo Cheng [email protected] Zsuzsanna Magyar [email protected] January 16, 2016 1 Section objectives In this section we will use the HW2.dta. This dataset is a small set of variables from the larger “Maddison dataset” 1 By the end, you should be comfortable using commands to import your .dta file, making (somewhat) fancy scatterplots, and running () regressions. 2 Commands In this lab, you should become familiar with the following commands. cd use
  • 2. regress and twoway scatter lfit scheme () 3 Set working directory and quickly running a .do file • Log in and open Stata. • Log in the class website. Save the Homework 2 data in “My Documents” (or any folder that works for you). • Open a .do file. First set the working directory on Stata. Type: cd "insert path address" To get the address of your path, right click on “My documents” and press “Copy address” so you can copy this inside your “” after cd. 1See here for more information: http://www.ggdc.net/maddison/maddison-project/home.htm. 1 • To import the data type the command use. Type: use HW2.dta
  • 3. • Check whether or not the data has been imported properly. • Now you know how to open your data using code. This means you can quickly run your .do file on a clean dataset using the clear all command at the top of the .do file. This will save you the trouble of opening a fresh dataset once your do file is finished. • To sum up, at the top of your .do file, type clear all cd "path address" use HW2.dta Question 1. How many variables are in the dataset, and how many observations are there? 4 Scatterplots • Everything after the “,” in a graphical command is an option. The variables being graphed come before the comma. • Sometimes it is nice to use a scheme for your scatterplot so it looks simpler. Here we use the scheme (s1mono). Schemes determine the overall look of a graph. • To draw scatterplots with observation labels and titles for the y and x axis. Type twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)), /// scheme (s1mono) ///
  • 4. ytitle("GDP per capita 2000") /// xtitle("GDP per capita 1500") /// title("Scatterplot of GDP per capita 1500 versus 2000") • Add a line of best fit using lfit command. Type: twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)) (lfit gdppc_2000 gdppc_ 1500, color(blue)), /// scheme (s1mono) /// ytitle("GDP per capita 2000") /// xtitle("GDP per capita 1500") /// title("Scatterplot of GDP per capita 1500 versus 2000") Question 2. What relationship does the slope of the fitted line indicate? 5 Linear regression • The dependent variable (or outcome variable) is what we are trying to explain. It is also called the “outcome” or Y . 2 • The explanatory (or independent variables) are what we use to do the explaining. These
  • 5. variables are also called predictors, as we think they are trying to predict the dependent variable. • The command for a regression is regress. • Now let’s run a regression. Note that your dependent variable always comes before the independent variable. You should remember what units you are working in in order to help you interpret your results. Type: regress gdppc_2000 gdppc_1500 Question 3. What is the outcome in this regression? What variable are we using to predict the outcome? How do we interpret the coefficient? 6 Summary statistics by continent • In Homework 1, you calculated the mean for each region by typing three lines of code. A quicker way to do this is to use the tabstat command followed by by. • Generate a single variable for continent. The straight vertical line means “or.” Type gen continent = . replace continent = 1 if africa == 1 replace continent = 2 if east_asia == 1 | west_asia ==1 | cent_asia ==1
  • 6. replace continent = 3 if latin_america ==1 replace continent = 4 if west_europe ==1 | east_europe ==1 replace continent = 5 if country == "United States" | country == "Canada" replace continent = 6 if country == "Australia" | country == "New Zealand" • Lets see what we have. tab continent • Now we label the new variable. label define contname 1 "Africa" 2 "Asia" 3 "Latin America" 4 "Europe" 5 "North America" 6 "Australia" label values continent contname • Suppose we want the mean population for each continent. tabstat pop_1820, statistics(mean) by(continent) 3 Section objectivesCommandsSet working directory and quickly running a .do fileScatterplotsLinear regressionSummary statistics by continent Lab 3: Set Working Directory, Scatterplots and Introduction to Linear Regression
  • 7. Chao-yo Cheng [email protected] Zsuzsanna Magyar [email protected] January 16, 2016 1 Section objectives In this section we will use the HW2.dta. This dataset is a small set of variables from the larger “Maddison dataset” 1 By the end, you should be comfortable using commands to import your .dta file, making (somewhat) fancy scatterplots, and running () regressions. 2 Commands In this lab, you should become familiar with the following commands. cd use regress and twoway scatter lfit
  • 8. scheme () 3 Set working directory and quickly running a .do file • Log in and open Stata. • Log in the class website. Save the Homework 2 data in “My Documents” (or any folder that works for you). • Open a .do file. First set the working directory on Stata. Type: cd "insert path address" To get the address of your path, right click on “My documents” and press “Copy address” so you can copy this inside your “” after cd. 1See here for more information: http://www.ggdc.net/maddison/maddison-project/home.htm. 1 • To import the data type the command use. Type: use HW2.dta • Check whether or not the data has been imported properly. • Now you know how to open your data using code. This means you can quickly run your .do file on a clean dataset using the clear all command at the top of the .do file. This will save you the trouble of opening a fresh dataset once
  • 9. your do file is finished. • To sum up, at the top of your .do file, type clear all cd "path address" use HW2.dta Question 1. How many variables are in the dataset, and how many observations are there? 4 Scatterplots • Everything after the “,” in a graphical command is an option. The variables being graphed come before the comma. • Sometimes it is nice to use a scheme for your scatterplot so it looks simpler. Here we use the scheme (s1mono). Schemes determine the overall look of a graph. • To draw scatterplots with observation labels and titles for the y and x axis. Type twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)), /// scheme (s1mono) /// ytitle("GDP per capita 2000") /// xtitle("GDP per capita 1500") /// title("Scatterplot of GDP per capita 1500 versus 2000") • Add a line of best fit using lfit command. Type:
  • 10. twoway (scatter gdppc_2000 gdppc_1500, mlabel(country)) (lfit gdppc_2000 gdppc_ 1500, color(blue)), /// scheme (s1mono) /// ytitle("GDP per capita 2000") /// xtitle("GDP per capita 1500") /// title("Scatterplot of GDP per capita 1500 versus 2000") Question 2. What relationship does the slope of the fitted line indicate? 5 Linear regression • The dependent variable (or outcome variable) is what we are trying to explain. It is also called the “outcome” or Y . 2 • The explanatory (or independent variables) are what we use to do the explaining. These variables are also called predictors, as we think they are trying to predict the dependent variable. • The command for a regression is regress. • Now let’s run a regression. Note that your dependent variable
  • 11. always comes before the independent variable. You should remember what units you are working in in order to help you interpret your results. Type: regress gdppc_2000 gdppc_1500 Question 3. What is the outcome in this regression? What variable are we using to predict the outcome? How do we interpret the coefficient? 6 Summary statistics by continent • In Homework 1, you calculated the mean for each region by typing three lines of code. A quicker way to do this is to use the tabstat command followed by by. • Generate a single variable for continent. The straight vertical line means “or.” Type gen continent = . replace continent = 1 if africa == 1 replace continent = 2 if east_asia == 1 | west_asia ==1 | cent_asia ==1 replace continent = 3 if latin_america ==1 replace continent = 4 if west_europe ==1 | east_europe ==1 replace continent = 5 if country == "United States" | country == "Canada"
  • 12. replace continent = 6 if country == "Australia" | country == "New Zealand" • Lets see what we have. tab continent • Now we label the new variable. label define contname 1 "Africa" 2 "Asia" 3 "Latin America" 4 "Europe" 5 "North America" 6 "Australia" label values continent contname • Suppose we want the mean population for each continent. tabstat pop_1820, statistics(mean) by(continent) 3 Section objectivesCommandsSet working directory and quickly running a .do fileScatterplotsLinear regressionSummary statistics by continent All tables and figures should be numbered and fully titled, e.g. Figure 1: Histogram of average per capita income, 1975 and 2009. All work must be concise and presented clearly. Write in complete and correct English sentences. Do not just give a number as an answer. Students lose points for unclear or incomplete presentation of data and findings. If the person reading and grading your assignment cannot understand what you are trying to say, they cannot give you full credit for your ideas. For full credit, please note which Stata command you used to obtain each part of the answer to each question One example how to interpret the slope (beta) coefficient is the following :
  • 13. On average, a (unit) increase in X (your independent variable) will be associated with SLOPE (unit) (increase/decrease) in Y (your dependent variable). Please fill in the terms in parentheses and in capital letters. Of course maybe you learned a slightly different language in another class and you are welcome to use that language. But do not forget to use the units of the variables and by all means include a version of the language "on average..” do not forget that the intercept (alpha or constant) is the the average of Y (or the predicted Y) when X is 0. Furthermore if you are comfortable with it you can provide a substantive interpretation of the coefficients, you can interpret the standard errors and the R^2-red. I know some of you may have forgotten some of this but we will have a review of the OLS model in this week’s section and of course you can look through your notes from your intro to stats classes as well.
  • 14. The goal of this assignment is to describe the historical growth of population and income around the world. All tables and figures should be numbered and titled, e.g. Figure 1: Scatterplot of GDP per capita in 1500 and 2000. I. The first set of questions can be answered using the dataset hw2.dta. 1.Compare the wealth of countries in 1600 to the wealth of countries in 2001. Are the wealthy countries in 1600 the same as the wealthy countries in 2001? In order to explore this question, first generate and report a scatter plot by country of gdp per capita in 1600 and gdp per capita in 2001. [Hint: Label the values on the scatter plot with country names using the mlabel() option.] To investigate the strength of the relationship, report a regression with gdp per capita in 2001 as the dependent variable and gdp per capita 1600 as the regressor. Interpret the results. 2. Report the mean gdp per capita in 1820 and 2001 by world region. [Hint: Use the "tabstat" command with the by() option.] What is the ratio of western Europe’s per capita gdp to the global average per capita gdp in 1820? And In 2001? What is western Europe’s income ratio in those years? Which regions were the poorest in 1820 and in 2001?
  • 15. 3. Compare the populations of countries in 1600 to their populations in 2001. Report a graph and regression that demonstrates the relationship. How strong is the relationship? [Hint: You may want to create new variables that are the logarithms of populations in the two periods to improve the graphic relationship. The Stata command log() takes the log of a value.] 4. What is the relationship of population to wealth in 1600? [Hint: This question is not asking you about the relations to per capita income.] In 2001? Generate a graphic and a statistical comparison in both periods and summarize the comparative relationship. [Hint: For graphical purposes, you again may want to use logarithmic values.] Create a third graph and regression to answer the following question: Have countries with larger populations in 1600 done better over the subsequent 401 years than countries which started with small populations? II. The final question can be answered using the dataset korea.dta. 5. Sort the data by year and report a table with the population and gdp per capita of South and North Korea for the dates that have data for both countries.
  • 16. Create a scatter plot using the following command: twoway (line gdppc year if country=="North Korea", clcolor(green) clpat(dash) legend(label(1 "North Korea") label(2 "South Korea"))) (line gdppc year if country=="South Korea", clcolor(red) clpat(dot) clwidth(medthick)) How would you interpret the data? What do they say about the importance of government institutions for economic growth? What alternative explanations can you think of? [Hint: Korea was a single country for most of the time period of this data set, wasoccupied by Japan beginning in 1905, and split into North (communist) and South(capitalist) at the end of WWII in 1945. See the CIA factbook for more information:https://www.cia.gov/library/publications/the-world- factbook/geos/kn.html.]