Monday, October 26, 2020

Converting string date to date - monthly function

Dear Stata users,

I need guidance to convert a string date to a numerical date. I tried using functions date() and monthly () but i wasn't able to solve it. I need this because I need to plot a twoway line graph.

Follows my data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str7 date float(ore elect)
"2013m1"  150.49 203.96
"2013m2"  154.63 108.69
"2013m3"  139.87 171.12
"2013m4"  137.39  97.98
"2013m5"  124.01 169.08
"2013m6"  114.81   95.5
"2013m7"  127.19  53.89
"2013m8"  137.05  69.64
"2013m9"  134.18 117.42
"2013m10" 132.57 119.12
"2013m11" 136.32 143.99
"2013m12" 135.79 123.85
"2014m1"  128.11 158.82
"2014m2"  121.37 345.59
"2014m3"  111.83  353.6
"2014m4"  114.58 368.77
"2014m5"  100.56  363.3
"2014m6"   92.85 184.66
"2014m7"   96.26 266.44
"2014m8"   94.14 313.04
"2014m9"   84.52 312.06
"2014m10"   81.3 317.06
"2014m11"  74.42 315.38
"2014m12"  68.67 227.08
"2015m1"   69.06 147.42
"2015m2"    63.8 137.78
"2015m3"   58.18 123.52
"2015m4"   52.11 127.65
"2015m5"   60.42 126.64
"2015m6"   61.84 119.87
"2015m7"   52.17  74.46
"2015m8"   57.33   41.3
"2015m9"   56.97   58.2
"2015m10"  53.66  54.79
"2015m11"  47.19  53.68
"2015m12"  40.88  29.94
"2016m1"    42.2   8.81
"2016m2"   46.48   7.67
"2016m3"   56.53  10.22
"2016m4"   60.96  13.91
"2016m5"   55.88  21.45
"2016m6"   52.34  17.94
"2016m7"   57.31  25.44
"2016m8"   60.87  36.02
"2016m9"   57.66  45.81
"2016m10"  58.95  62.83
"2016m11"  74.13   49.7
"2016m12"  79.43  36.49
"2017m1"   80.82  37.98
"2017m2"   88.96  41.39
"2017m3"   87.19  69.16
"2017m4"    70.4 118.36
"2017m5"   61.63 128.28
"2017m6"   57.86  37.84
"2017m7"   66.74  87.74
"2017m8"   74.58 160.47
"2017m9"   69.24  166.5
"2017m10"  61.05 167.13
"2017m11"  63.49 130.38
"2017m12"  71.74  71.28
"2018m1"   75.79  56.05
"2018m2"   77.65   58.1
"2018m3"   71.32  66.85
"2018m4"   66.33  32.18
"2018m5"   66.63  89.52
"2018m6"   66.86 124.96
"2018m7"   67.05  132.1
"2018m8"   68.02 128.51
"2018m9"    68.8 115.07
"2018m10"  72.02  71.22
"2018m11"   72.3  32.71
"2018m12"   68.9  20.31
"2019m1"    75.2  51.35
"2019m2"   87.59 119.15
"2019m3"   87.07  61.06
"2019m4"    94.5  46.29
"2019m5"  101.76  33.83
"2019m6"  109.55  20.35
"2019m7"  119.58  49.06
"2019m8"    93.5   58.9
"2019m9"   92.26  53.26
"2019m10"  88.58  67.02
"2019m11"   82.9  76.25
"2019m12"  90.98  55.38
end
Thank you all,
Max

No comments:

Post a Comment