@fanxy
2016-07-05T19:56:25.000000Z
字数 1246
阅读 2104
樊潇彦
复旦大学经济学院
经济数学
# 准备工作
setwd("D:\\...")
rm(list=ls())
install.packages("dplyr")
install.packages("data.table")
install.packages("ggplot2")
library(dplyr)
library(data.table)
library(ggplot2)
数据下载
Ch3_data.rar128.1kB
engel=read.csv("CME_Consmp3.csv",header=T,skip=2,stringsAsFactors = F)
engel1=engel[,c(1,2,6)]
engel2=engel[,c(1,3,7)]
colnames(engel1)=colnames(engel2)=c("year","inc","engel")
engel=rbind(data.frame(urbdum=0,engel1),data.frame(urbdum=1,engel2))
engel=engel%>%
filter(year>=1980 & year<=2013)%>%
mutate(urbdum=as.factor(urbdum))%>%
arrange(urbdum,year)
ggplot(data=engel,aes(x=inc,y=engel,group=urbdum,color=urbdum)) +
geom_path()+
labs(title ="城乡居民家庭恩格尔系数(%)", x = "", y = "") +
theme_bw()
Exdata=read.csv("FE_Exrated.csv",header=T,stringsAsFactors = F)
Exdata=Exdata%>%
mutate(Date=as.Date(Date))%>%
arrange(Curcd,Date)
colnames(Exdata)=c("Date","Currency","E")
Ex=Exdata%>%
filter(Currency %in% c("USD","EUR","JPY"))
Ex$E[which(Ex$Currency!="JPY")]=Ex$E[which(Ex$Currency!="JPY")]/100 # 美元和欧元转换为1单位外币兑人民币
Ex$E[which(Ex$Date==as.Date("2014-11-18") & Ex$Currency=="JPY")]=5.265000 # 修正错误数据
ggplot(data=Ex,aes(x=Date,y=E,color=Currency))+
geom_line()+
labs(title ="人民币基准汇价", x = "", y = "") +
theme_bw()