Re: [Gretl-users] extracting month number
On Sun, 16 Sep 2012, Data Analytics Corp. wrote: > Hi, > > I have a monthly time series of the Dow Jones Industrial Index beginning > 1928:10. I'd like to create a new variable that is just the month > number: 10, 11, 12, 1, 2, 3, How can I do this? I thought there > would be a month function in Gretl, but I don't see one. This question, > of course, extends to the year (1928, 1928, 1929, 1929,...) and quarter > if I have quarterly data. Does this help? open bjg.gdt series year = 1949 + floor((t-1)/12) series month = 1 + ((t-1)%12) -- Riccardo (Jack) Lucchetti Dipartimento di Economia Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucchetti(a)univpm.it http://www2.econ.univpm.it/servizi/hpp/lucchetti --
Re: [Gretl-users] extracting month number
Very compact, as always. But it wouldn't work for a dataset with weekly or daily frequency, would it? Jan Annaert UNIVERSITEITANTWERPEN | Faculty of Applied Economics (TEW) | Dept. Accounting & Finance Room S.B.335 | Prinsstraat 13 | B-2000 Antwerp | Belgium Phone +32 32654163 |Fax +32 32654064 http://www.ua.ac.be/jan.annaert http://ssrn.com/author=143473 From: "Riccardo Lucchetti (Jack)" mailto:r.lucchetti(a)univpm.it>> Reply-To: "r.lucchetti(a)univpm.it<mailto:r.lucchetti(a)univpm.it>" mailto:r.lucchetti(a)univpm.it>>, "gretl-users(a)lists.wfu.edu<mailto:gretl-users(a)lists.wfu.edu>" mailto:gretl-users(a)lists.wfu.edu>> List-Post: gretl-users@gretlml.univpm.it Date: zondag 16 september 2012 22:40 To: "walt(a)dataanalyticscorp.com<mailto:walt(a)dataanalyticscorp.com>" mailto:walt(a)dataanalyticscorp.com>>, "gretl-users(a)lists.wfu.edu<mailto:gretl-users(a)lists.wfu.edu>" mailto:gretl-users(a)lists.wfu.edu>> Subject: Re: [Gretl-users] extracting month number On Sun, 16 Sep 2012, Data Analytics Corp. wrote: Hi, I have a monthly time series of the Dow Jones Industrial Index beginning 1928:10. I'd like to create a new variable that is just the month number: 10, 11, 12, 1, 2, 3, How can I do this? I thought there would be a month function in Gretl, but I don't see one. This question, of course, extends to the year (1928, 1928, 1929, 1929,...) and quarter if I have quarterly data. Does this help? open bjg.gdt series year = 1949 + floor((t-1)/12) series month = 1 + ((t-1)%12) -- Riccardo (Jack) Lucchetti Dipartimento di Economia Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucchetti(a)univpm.it<mailto:r.lucchetti(a)univpm.it> http://www2.econ.univpm.it/servizi/hpp/lucchetti -- Very compact, as always. But it wouldn't work for a dataset with weekly or daily frequency, would it? Jan Annaert UNIVERSITEITANTWERPEN | Faculty of Applied Economics (TEW) | Dept. Accounting & Finance Room S.B.335 | Prinsstraat 13 | B-2000 Antwerp | Belgium Phone +32 32654163 |Fax +32 32654064 http://www.ua.ac.be/jan.annaert http://ssrn.com/author=143473 From: "Riccardo Lucchetti (Jack)" <r.lucche...@univpm.it> Reply-To: "r.lucche...@univpm.it" <r.lucche...@univpm.it>, "gretl-us...@lists.wfu.edu" <gretl-us...@lists.wfu.edu> Date: zondag 16 september 2012 22:40 To: "w...@dataanalyticscorp.com" <w...@dataanalyticscorp.com>, "gretl-us...@lists.wfu.edu" <gretl-us...@lists.wfu.edu> Subject: Re: [Gretl-users] extracting month number On Sun, 16 Sep 2012, Data Analytics Corp. wrote: Hi, I have a monthly time series of the Dow Jones Industrial Index beginning 1928:10. I'd like to create a new variable that is just the month number: 10, 11, 12, 1, 2, 3, How can I do this? I thought there would be a month function in Gretl, but I don't see one. This question, of course, extends to the year (1928, 1928, 1929, 1929,...) and quarter if I have quarterly data. Does this help? open bjg.gdt series year = 1949 + floor((t-1)/12) series month = 1 + ((t-1)%12) -- Riccardo (Jack) Lucchetti Dipartimento di Economia Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucche...@univpm.it http://www2.econ.univpm.it/servizi/hpp/lucchetti --
Re: [Gretl-users] extracting month number
On Mon, 17 Sep 2012, Annaert Jan wrote: > Very compact, as always. But it wouldn't work for a dataset with weekly > or daily frequency, would it? For daily data, I can't see why not. For weekly data, the problem is that 365 is not a multiple of 7. -- Riccardo (Jack) Lucchetti Dipartimento di Economia Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucchetti(a)univpm.it http://www2.econ.univpm.it/servizi/hpp/lucchetti --
Re: [Gretl-users] extracting month number
On 16/09/12 22:40, Riccardo (Jack) Lucchetti wrote: > ... > Does this help? > > > open bjg.gdt > series year = 1949 + floor((t-1)/12) > series month = 1 + ((t-1)%12) > > > -- > Riccardo (Jack) Lucchetti > Dipartimento di Economia A different possibility is to play with strings. We have the command 'obslabel' for this. For example, if the observations are quarterly, this code writes the year of the 't' observation into the string 'iyear' and the quarter into the string 'iquarter': (where t=1, 2, 3, ... is the 1-based index of the observation: ) string s = obslabel(t) sscanf s, "%d:%d", tyear, tquarter If you need it, you may then put the strings in scalars in this way: scalar ty=@tyear scalar tq=@tquarter -- Ignacio Diaz-Emparanza DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA) UPV/EHU Avda. Lehendakari Aguirre, 83 | 48015 BILBAO T.: +34 946013732 | F.: +34 946013754 www.ehu.es/ignacio.diaz-emparanza/ www.ea3.ehu.es
Re: [Gretl-users] extracting month number
On 17/09/12 11:29, Ignacio Diaz-Emparanza wrote: > A different possibility is to play with strings. We have the command > 'obslabel' for this. For example, if the observations are quarterly, > this code writes the year of the 't' observation into the string > 'iyear' and the quarter into the string 'iquarter': Sorry, in the script the strings were defined as "tyear" and "tquarter" instead of "iyear" and "iquarter". -- Ignacio Diaz-Emparanza DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA) UPV/EHU Avda. Lehendakari Aguirre, 83 | 48015 BILBAO T.: +34 946013732 | F.: +34 946013754 www.ehu.es/ignacio.diaz-emparanza/ www.ea3.ehu.es
Re: [Gretl-users] extracting month number
On Mon, 17 Sep 2012, Ignacio Diaz-Emparanza wrote: > A different possibility is to play with strings. We have the command > 'obslabel' for this. > For example, if the observations are quarterly, this code writes the > year of the 't' observation into the string 'iyear' and the quarter into > the string 'iquarter': (where t=1, 2, 3, ... is the 1-based index of the > observation: ) > > > string s = obslabel(t) > sscanf s, "%d:%d", tyear, tquarter > > > If you need it, you may then put the strings in scalars in this way: > > scalar ty=@tyear > scalar tq=@tquarter Hmm, the "%d" conversion already produces a scalar. If series results are wanted, here's a variant on Ignacio's suggestion. It's bulkier than Jack's suggestion, but it doesn't depend on knowing the starting year and quarter in advance: open data9-7 series quarter year scalar tyear tquart string s loop t=1..$nobs -q s = obslabel(t) sscanf s, "%d:%d", tyear, tquart year[t] = tyear quarter[t] = tquart endloop print year quarter --byobs Allin Cottrell
Re: [Gretl-users] extracting month number
On Mon, 17 Sep 2012, Allin Cottrell wrote: > If series results are wanted, here's a variant on Ignacio's > suggestion. It's bulkier than Jack's suggestion, but it doesn't > depend on knowing the starting year and quarter in advance: > > > open data9-7 > series quarter year > scalar tyear tquart > string s > loop t=1..$nobs -q > s = obslabel(t) > sscanf s, "%d:%d", tyear, tquart > year[t] = tyear > quarter[t] = tquart > endloop > > print year quarter --byobs > Thinking about this, it seemed lame that you had to use temporary scalar variables to accept the result of scalar conversions from sscanf -- rather than assigning the results directly to elements of series (or matrices). That's now fixed: the following nicer version will work with current CVS: open data9-7 series quarter year string s loop t=1..$nobs -q s = obslabel(t) sscanf s, "%d:%d", year[t], quarter[t] endloop This will be in the snapshots for Windows and Mac tomorrow. Allin Cottrell