0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Penn World Table(PWT)をGoogle Colab 上のR環境でいじってみた

Last updated at Posted at 2023-05-12

はじめに

Goole Colab 上のR環境で、マクロ経済のデータベースであるPenn World Table(PWT) https://www.rug.nl/ggdc/productivity/pwt/ を使ってみることにした。こういうデータベースを使う以上、日本のデータだけというのは無意味な気もするが、とりあえず今回は日本の実質GDPの時系列グラフを描くことにした。

実行環境

Goole Colab でのR環境の構築方法については https://htsuda.net/stats/colab.html を参考にさせていただいた。

データ

現行バージョンのPWT10.01 は、183か国のrgdpe(実質GDP(支出面))、rgdpo(実質GDP(生産面))、hc(人的資本)などを含む48の時系列データ(1950年から2019年まで)が提供されている。

今回はRのパッケージでこのデータベースを使ってみる。

CRANのサイト( https://cran.r-project.org/web/packages/available_packages_by_name.html )をみると、PWTのRパッケージは古いものを含め、以下のように複数ある。
pwt   Penn World Table (Versions 5.6, 6.x, 7.x)
pwt10  Penn World Table (Version 10.x)
pwt8  Penn World Table (Version 8.x)
pwt9  Penn World Table (Version 9.x)

2019年までのデータを含む最新のものにしておきたいので、pwt10を使う。

install.packages("pwt10")
library("pwt10")

ここで、

data()

と確認してみると、
image.png
と表示され、pwt10.0 とpwt10.01が使えることが分かる(チェックしてみると、データフレーム型)。

この後描くグラフだけなら、追加のライブラリーは"ggplot2"だけでよさそうだが、データ分析によく使われる他のものを含む"tidyverse"のロードまたはインストールをしておくことにした。

if (!require("tidyverse")) install.packages("tidyverse")

グラフ描画のコード

pwt10.01から日本のデータだけ取り出してグラフを描く。

# 日本のデータのみ選択
data_selected <- pwt10.01 %>% filter(country == "Japan")

# rgdpo の時系列グラフ
ggplot(data = data_selected, aes(x = year, y = rgdpo)) +
  geom_line() +
  labs(title = "Real GDP of Japan (1950-2019)",
       x = "Year",
       y = "Real GDP")

出力結果は以下の通り。
image.png

おわりに

これまでPWTの存在は知っていたが、Rのパッケージの存在は知らなかった。できるのかわからないが、次はPythonで試してみたい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?