@fanxy 2016-07-05T11:56:25.000000Z 字数 1246 阅读 1741

# 第三讲 经济学中的函数和方程

樊潇彦 复旦大学经济学院 经济数学

Ch03.pdf1398.3kB

# 2. 作图程序附录

# 准备工作setwd("D:\\...")rm(list=ls())install.packages("dplyr")install.packages("data.table")install.packages("ggplot2")library(dplyr)library(data.table)library(ggplot2)

## 2.1 恩格尔定律

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()

## 2.2 汇率

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()

• 私有
• 公开
• 删除