Thanks Allin & Jack,
I forgot to mention that I'm using the cvs build from 6/5 on Windows 7.
Anyway, I just closed Gretl & restarted it, and now everything works fine. I'm
still figuring out the "%" fields, so the %02d suggestion is very helpful. The
only concern I still have is that this will eventually (hopefully soon!) be part of a
public function package, so hopefully it's just an isolated incident.
From: gretl-users-bounces(a)lists.wfu.edu [mailto:email@example.com] On
Behalf Of Allin Cottrell
Sent: Friday, June 14, 2013 9:39 AM
To: Gretl list
Subject: Re: [Gretl-users] bug in string substitution?
On Thu, 13 Jun 2013, Summers, Peter wrote:
I'm trying to generate a matrix of "dates" that I can
use on the
x-axis of graphs of forecasts. I want the format to be "yyyy.q" or
"yyyy.mm" for quarterly or monthly data, respectively. Things work
fine for quarterly data, but something weird happens with monthly
I create a string with the desired format, then make the corresponding
matrix entry using string substitution. So for example the string
"2009.04" should just become the "number"
2009.04. However, the string substitution results in the second
"decimal" being truncated, so I get 2009.0 instead of 2009.04, or
2009.1 instead of 2009.12.
The attached script illustrates the problem.
Hmm, I'm not seeing a problem here (current CVS on Linux). But note that the
recommended way to get a month to appear in the desired format with sprintf is to use the
(which inserts a zero if and only if it's needed).
If I do
scalar yr = 2009
scalar mo = 4
sprintf s, "%d.%02d", yr, mo
printf "s = '%s'\n", s
scalar d = @s
? scalar yr = 2009
Generated scalar yr = 2009
? scalar mo = 4
Generated scalar mo = 4
? string s
? sprintf s, "%d.%02d", yr, mo
s = '2009.04'
? scalar d = 2009.04
Generated scalar d = 2009.04
Gretl-users mailing list