[关闭]
@fanxy 2016-09-27T17:35:01.000000Z 字数 3291 阅读 1877

第四讲 地方政府债务:改革、发展与案例分析

樊潇彦 复旦大学经济学院 中级宏观


  1. library(readxl) # 读取excel数据
  2. library(stringr) # 字符串处理
  3. library(corrplot)
  4. library(igraph)
  5. library(forecast)
  6. library(stats) # 基础包,不用安装直接调用
  7. library(dplyr)
  8. library(tidyr)
  9. library(data.table)
  10. library(foreign)
  11. library(readstata13)
  12. library(haven)
  13. library(ggplot2)
  14. library(ggrepel)
  15. library(dygraphs)
  16. library(plotrix)
  17. library(lubridate)
  18. library(zoo)
  19. library(mFilter)
  20. setwd("D:\\") # 设定工作目录

1. 土地出让收入

  1. total=read_excel("../Ch03/Ch03_Data.xls",sheet="total",skip=1)
  2. local_inc=total%>%
  3. mutate(year=as.numeric(year(`指标名称`)))%>%
  4. mutate(local_inc=`国家财政收入`*(100-`中央财政收入:占比`)/100)%>%
  5. select(year,local_inc)
  6. land=read_excel("Ch04_Data.xlsx",sheet="land")
  7. str(land)
  8. land=land%>%
  9. filter(`单位` %in% c("万元") & !grepl('招拍挂|协议',`指标名称`))%>%
  10. select(-`单位`,-`指标ID`)%>%
  11. rename(region=`指标名称`)%>%
  12. gather(year,value,-region)%>%
  13. mutate(year=as.numeric(year))%>%
  14. filter(!is.na(value))%>%
  15. mutate(value=value/10000)%>%
  16. mutate(region=sub("土地出让成交价款:","",region))%>%
  17. left_join(local_inc,by="year")%>%
  18. mutate(land2inc=ifelse(region=="全国",value/local_inc,NA))%>%
  19. select(-local_inc)%>%
  20. arrange(year,value)
  21. g_land=land[land$region=="全国",]
  22. twoord.plot(lx = g_land$year, ly = g_land$value,
  23. rx = g_land$year, ry = g_land$land2inc,
  24. main = '土地财政', xlab = '',
  25. ylab = '土地出让收入(万元)', rylab = '占地方财政收入之比',
  26. type = c('line','line'))
  27. ggplot(land[!land$region %in% c("全国","西藏"),],aes(year,value)) +
  28. geom_line()+facet_wrap(~region,ncol=5)+
  29. labs(title = "各地区土地出让收入(万元)",x="",y="")+
  30. theme_bw()

2. 地方债发行月度数据

  1. debt_mm=read_excel("Ch04_Data.xlsx",sheet="debt_mm",col_types=c("date",rep("numeric",5)))
  2. debt_mm=debt_mm%>%
  3. mutate(time=as.Date(`日期`))%>%
  4. select(-`日期`,-`总计`)%>%
  5. gather(var,value,-time)%>%
  6. filter(!is.na(value))
  7. ggplot(debt_mm,aes(time,value,fill=var))+
  8. geom_bar(stat="identity")+
  9. labs(title="地方债发行:按类别分月度数据",x="",y="")+
  10. guides(fill=guide_legend(title=NULL))+
  11. theme_bw()+theme(legend.position="bottom")

3. 地方债利率

  1. cen_loc=read_excel("Ch04_Data.xlsx",sheet="cen_loc",skip=1)
  2. str(cen_loc)
  3. cen_loc=cen_loc%>%
  4. rename(time=`指标名称`)%>%
  5. gather(var,i,-time)%>%
  6. filter(!is.na(i))%>%
  7. mutate(type=substr(var,5,6))%>%
  8. mutate(type=ifelse(type=="地方","地方债",type))%>%
  9. mutate(term=sub(".*:","",var))%>%
  10. select(-var)
  11. ggplot(cen_loc,aes(time,i,color=type))+geom_point()+geom_smooth()+
  12. facet_wrap(~term,ncol=3)+labs(title="不同期限地方债和国债发行利率",x="",y="")+
  13. guides(color = guide_legend(title = NULL)) +
  14. theme_bw()+ theme(legend.position = 'bottom')

4. 城投债利率

  1. cityinv=read_excel("Ch04_Data.xlsx",sheet="cityinv",skip=1,
  2. col_types=c("date",rep("numeric",226)))
  3. str(cityinv)
  4. cityinv=cityinv%>%
  5. rename(time=`指标名称`)%>%
  6. gather(var,i,-time)%>%
  7. filter(!is.na(i))%>%
  8. mutate(market=substr(var,1,2))%>%
  9. mutate(type=sub(".*城投债","",var))%>%
  10. mutate(type=sub("收益率.*","",type))%>%
  11. mutate(grade=sub(".*\\(","",var))%>%
  12. mutate(grade=sub("\\).*","",grade))%>%
  13. mutate(term=sub(".*:","",var))%>%
  14. select(-var)
  15. # 查看数据
  16. summary(cityinv$time[cityinv$market=="银行"]) # 银行间市场从2012-01-09开始
  17. summary(cityinv$time[cityinv$market=="中债"]) # 中债从2008-08-13开始
  18. table(cityinv$market,cityinv$grade) # 中债评级有AAA
  19. table(cityinv$market,cityinv$type) # 银行间有远期收益率
  20. table(cityinv$market,cityinv$term) # 中债6个月标记为0年,银行间没有9年
  21. g=cityinv%>%
  22. filter(market=="中债" & type=="到期" &
  23. grade %in% c("AA-","AAA") & term %in% c("1年","3年","10年"))
  24. ggplot(g,aes(time,i,color=term))+geom_line()+facet_wrap(~grade,ncol=2)+
  25. labs(title="中债城投债到期收益率",x="",y="")+
  26. guides(color=guide_legend(title=NULL))+
  27. theme_bw()+theme(legend.position="bottom")
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注