Sven,
I hope this is what you are asking for.
Variable names:
UR in Dunn Co WI: WIDUNN3URN
UR in Washington Co WI: MNWASH5URN
Here is the function I have written to flatten the dataset (please do not look too closely
I have not made it very pretty yet):
function void flatten(string filename, lists inlsts, strings incats, strings invars)
#Needs error checking--VERY FRAGLE
/*
Summary: Creates a flat file from a panel of time series
Discription: Stacks time series variables by category arranging variables in
columns and adds a category variable.
Example:
*/
series isobasic = $obsdate
series y, m, d
isoconv(isobasic, &y, &m, &d)
matrix date = {y}~{m}~{d}
scalar T = rows(date)
scalar C = nelem(incats)
scalar N = nelem(invars)
strings dates = array(T)
loop i = 1..rows(date) --quiet
dates[i] = sprintf("%d-%02d-%02d",date[i,1],date[i,2],date[i,3])
endloop
matrix stack
loop i = 1..nelem(inlsts) --quiet
stack ~= vec({inlsts[i]})
endloop
matrix date =
mshape({isobasic},rows(stack),1)~mshape({y},rows(stack),1)~mshape({m},rows(stack),1)~mshape({d},rows(stack),1)
string obrow, dtrow tprow
loop n = 1..N --quiet
tprow = tprow ~ "," ~ sprintf("%s", invars[n])
endloop
outfile "(a)filename.csv" --write
printf "%s,%s,%s,%s,%s,%s%s\n", "date", "category",
"isobasic","year","month","day",tprow
loop c = 1..C --quiet
loop t = 1..T --quiet
scalar indx = c * t
loop k = 1..N --quiet
obrow = obrow ~ "," ~ sprintf("%f", stack[indx,k])
endloop
loop k = 1..4 --quiet
dtrow = dtrow ~ "," ~ sprintf("%d", date[indx,k])
endloop
printf "%s,%s%s%s\n", dates[t], incats[c], dtrow, obrow
dtrow = ""
obrow = ""
endloop
endloop
outfile --close
end function
-----Original Message-----
From: gretl-devel-bounces(a)lists.wfu.edu [mailto:gretl-devel-
bounces(a)lists.wfu.edu] On Behalf Of Sven Schreiber
Sent: Monday, December 01, 2014 10:28 AM
To: gretl-devel(a)lists.wfu.edu
Subject: Re: [Gretl-devel] is there an inarray function?
Am 01.12.2014 um 17:23 schrieb Logan Kelly:
> Yes, I am going to output to a csv file, but it is time series data that is trying
very hard to be panel. I am working with regional data (at the State and
County level) for a web visualization, so I have, say, the unemployment rate
for each country and each state in my region that I need to stack (see
example below). It is not too difficult, but I want to be able to redefine the
data set using a definition file that can be edited in excel (so a student
assistant can work with it).
>
>
> Date State County UR
> 2005:01 WI DUNN 5% #value is just made up
> 2005:02 WI DUNN 6% #value is just made up
> 2005:01 MN WASH 3% #value is just made up
> 2005:02 MN WASH 4% #value is just made up
>
>
can you give an example or even better the pattern how your variables are
named?
-s
_______________________________________________
Gretl-devel mailing list
Gretl-devel(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel