Hi everyone,
It is the first time I work with time series, so I am not proficient at all.
I would like to create a graph in which we observe, for each month from January 2021 onwards, the number of households that adopted new solar photovoltaic (PV) systems to their houses.
I'd like to do it, but cumulatively: For example, if in January 2021, only one household has adopted a solar panel, and in February 2021, two households have installed a PV system, I'd like these two figures to add up, and so on.
I'd like to do this by power distinction in kilowatts. Here's an example of the code I've tried to implement:
However I obtain an error message:
Please also find attached a -dataex-. I reduced the number of variables for better readability:
The graph that I would like to obtain is similar to the one presented below.
Could anyone give me a hand with this, please?
Thank you very much in advance.
Best,
Michael
It is the first time I work with time series, so I am not proficient at all.
I would like to create a graph in which we observe, for each month from January 2021 onwards, the number of households that adopted new solar photovoltaic (PV) systems to their houses.
I'd like to do it, but cumulatively: For example, if in January 2021, only one household has adopted a solar panel, and in February 2021, two households have installed a PV system, I'd like these two figures to add up, and so on.
I'd like to do this by power distinction in kilowatts. Here's an example of the code I've tried to implement:
Code:
********************************************************* // only solar panels adopters --> Cumulative Monthly installations ********************************************************* preserve gen cap_2kw=0 gen cap_4kw=0 gen cap_6kw=0 gen cap_8kw=0 gen cap_10kw=0 replace cap_2kw=1 if kW_power_p1<=2 & !missing(cap_2kw) replace cap_4kw=1 if kW_power_p1<=4 & kW_power_p1>2 & !missing(cap_4kw) replace cap_6kw=1 if kW_power_p1<=6 & kW_power_p1>4 & !missing(cap_6kw) replace cap_8kw=1 if kW_power_p1<=8 & kW_power_p1>6 & !missing(cap_8kw) replace cap_10kw=1 if kW_power_p1>8 & !missing(cap_10kw) gen cap=0 order cap, after(date_contract_end) replace cap=2 if cap_2kw==1 replace cap=4 if cap_4kw==1 replace cap=6 if cap_6kw==1 replace cap=8 if cap_8kw==1 replace cap=10 if cap_10kw==1 bysort year month : egen cum_2kw = sum(cap_2kw) bysort year month : egen cum_4kw = sum(cap_4kw) bysort year month : egen cum_6kw = sum(cap_6kw) bysort year month : egen cum_8kw = sum(cap_8kw) bysort year month : egen cum_10kw = sum(cap_10kw) tsline cum_2kw cum_4kw cum_6kw cum_8kw cum_10kw if date_contract_start>=td(01jan2021), /// ytitle("Total PV adoptions") ylabel(#5) /// ttitle("") tlabel(2006m1 "2006" 2007m1 "2007" 2008m1 "2008" 2009m1 "2009" 2010m1 "2010" 2011m1 "2011" 2012m1 "2012" 2013m1 "2013") /// ttitle("") lcolor(black) legend(rows(1)) /// lcolor(navy maroon green orange gray) /// lwidth(vvthin thin medthin medium medthick) xsize(8) /// scheme(white_w3d) restore
Code:
time variable not set, use tsset varname ... r(111);
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id double(date_contract_start date_contract_end date_pv_install) float(year month cap_4kw count_pv_monthly_cumulative_4kw) 220419 21242 21994 21875 2019 11 0 5 226063 21293 22431 22336 2021 2 0 4 52917 21328 22267 21875 2019 11 0 5 233526 21468 22431 21875 2019 11 0 5 280061 21519 22398 22376 2021 4 0 2 266559 21559 21966 21875 2019 11 0 5 25807 21571 22102 21875 2019 11 0 5 304314 21578 21994 21875 2019 11 1 5 309928 21594 22431 22407 2021 5 0 9 312268 21600 22431 22356 2021 3 1 8 end format %td date_contract_start format %td date_contract_end format %td date_pv_install
The graph that I would like to obtain is similar to the one presented below.
Could anyone give me a hand with this, please?
Thank you very much in advance.
Best,
Michael