[关闭]
@fanxy 2016-07-05T11:56:25.000000Z 字数 1246 阅读 1444

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

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


1. 课件下载

Ch03.pdf1398.3kB

2. 作图程序附录

  1. # 准备工作
  2. setwd("D:\\...")
  3. rm(list=ls())
  4. install.packages("dplyr")
  5. install.packages("data.table")
  6. install.packages("ggplot2")
  7. library(dplyr)
  8. library(data.table)
  9. library(ggplot2)

数据下载
Ch3_data.rar128.1kB

2.1 恩格尔定律

  1. engel=read.csv("CME_Consmp3.csv",header=T,skip=2,stringsAsFactors = F)
  2. engel1=engel[,c(1,2,6)]
  3. engel2=engel[,c(1,3,7)]
  4. colnames(engel1)=colnames(engel2)=c("year","inc","engel")
  5. engel=rbind(data.frame(urbdum=0,engel1),data.frame(urbdum=1,engel2))
  6. engel=engel%>%
  7. filter(year>=1980 & year<=2013)%>%
  8. mutate(urbdum=as.factor(urbdum))%>%
  9. arrange(urbdum,year)
  10. ggplot(data=engel,aes(x=inc,y=engel,group=urbdum,color=urbdum)) +
  11. geom_path()+
  12. labs(title ="城乡居民家庭恩格尔系数(%)", x = "", y = "") +
  13. theme_bw()

2.2 汇率

  1. Exdata=read.csv("FE_Exrated.csv",header=T,stringsAsFactors = F)
  2. Exdata=Exdata%>%
  3. mutate(Date=as.Date(Date))%>%
  4. arrange(Curcd,Date)
  5. colnames(Exdata)=c("Date","Currency","E")
  6. Ex=Exdata%>%
  7. filter(Currency %in% c("USD","EUR","JPY"))
  8. Ex$E[which(Ex$Currency!="JPY")]=Ex$E[which(Ex$Currency!="JPY")]/100 # 美元和欧元转换为1单位外币兑人民币
  9. Ex$E[which(Ex$Date==as.Date("2014-11-18") & Ex$Currency=="JPY")]=5.265000 # 修正错误数据
  10. ggplot(data=Ex,aes(x=Date,y=E,color=Currency))+
  11. geom_line()+
  12. labs(title ="人民币基准汇价", x = "", y = "") +
  13. theme_bw()
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注