Econometrics 1 - Introduction - To - Econometrics - Using - R
Econometrics 1 - Introduction - To - Econometrics - Using - R
–
An Introduction for Research & Business using R
Université Paris-Sud
References
o Jeffrey Wooldridge, Introductory Econometrics: A Modern Approach, 3rd Edition,
2006
o William Green, Econometric Analysis, Prentice Hall, 6th Edition, 2008
o Florian Heiss, Using R for introductory econometrics, 2016
Definition
– The main variable under study, or the explained variable (wage, location choice,
migration choice, etc.)
– which is affected by other factors, or explicative variables (income, age, gender,
consumption, education, etc.)
For instance, does education affect wage? And if so, what is the return of an additional
year of education on wage?
3. Install the car and wooldridge packages for applied regression. Other packages will
be introduced during the course!
For importing files, use "Import dataset" in the ’Environment’ window and choose the
dataset format among csv (including text), Excel, SAS, SPSS or Stata
library(readxl)
HousePrices3 <- read_excel("C:/...HousePrices3.xlsx")
Script to keep record of your work on the dataset (new var., graphics, models, etc.):
- In RStudio: File => New File => R Script
- Write command(s), select it and click on run
- Add comments using # at the beginning of a line
HousePrices3 variables:
- year: year of information collection (1978 or 1981)
- age: age of the house
- nbh: neighborhood, 0 to 6
- cbd: distance (feet) to Central Business District
- inst: distance (feet) to interstate
- price: selling price
- rooms: # rooms in house
- area: square footage of house
- land: square footage of lot
- baths: # of bathrooms
- dist: distance (feet) to incinerator
Math operators in R:
- Usual math operators: - , + , / and *
- Inferior/inferior or equal/superior/superior or equal: <, <=, >, >=
- Is equal to (comparison operator in condition/constraint): ==
Logical operators in R:
- AND: &, e.g. [HousePrices3$rooms>=5 & HousePrices3$baths>3] computes the
command only for obs. in HousePrices3 which have rooms>=5 AND baths>3
- OR: | pronounced ’tube’ or ’pipe’ (Mac: Maj + alt + L, or PC: Alt Gr + 6), e.g.
[HousePrices3$rooms>=5 | HousePrices3$area>2000] computes the command only
for observations in HousePrices3 which have rooms>=5 OR area>2000
- NOT: !=, e.g. [HousePrices3$rooms!=5] computes the command only for
observations in HousePrices3 which have variable rooms NOT EQUAL to 5
Or, duplicate the variable then delete the old variable (here cbdmeters):
HousePrices3$cbdm <- HousePrices3$cbdmeters
HousePrices3 <- HousePrices3[-c(HousePrices3$cbdmeters)]
Boxplot boxplot(x)
library(vcd)
isLarge <- as.numeric(HousePrices3$areasm >= 110)
mosaic(~ isRecent + isLarge + nbh4,
data = HousePrices3, shade=TRUE, legend=TRUE )
Commented examples:
https://www.harding.edu/fmccown/r/
https://www.statmethods.net/graphs/line.html
https://en.wikibooks.org/wiki/R_Programming/Graphics