On Thu, 8 Aug 2013, Logan Kelly wrote:
> Hello,
>
> I need to delete a series inside a loop. Is there a way to do this? What I am
doing is loading data on a country, process the data, save some results,
replace the data with the next country's in my data set. Below is my code
that does not work:
>
> loop i = 1..numcountry
> cc = strsplit(ccode,i)
> append "(a)datafile.xlsx" --time-series --sheet="@cc"
--coloffset=0
> --rowoffset=1
>
> #Do some stuff
>
> delete Q* # yields an error
> delete R* # would yield an error if previous line did not end loop
>
> This of course yields the error:
>
> You cannot delete series in this context
>
> I understand that delete does not work in a loop, but is there a work
around? Or a better way to handle repeated processes?
Why not just wrap everything into a function and then call the funciton from
within the loop? That will take care of thrashing local variables automatically.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
Why not just wrap everything into a function and then call the
function from
within the loop? That will take care of thrashing local variables automatically.
OK. open does not work in a function, so I did not think to try append.
So here is my test:
set echo off
set messages off
set skip_missing off
clear
string datafile ="@workdir\EMU_RAW"
open "(a)datafile.xlsx" --preserve --sheet=1 --coloffset=0 --rowoffset=1
function void opendata(string file, string cc)
append "(a)file.xlsx" --time-series --sheet="@cc" --coloffset=0
--rowoffset=1 --quiet
end function
opendata(datafile, "BD")
This causes Gretl to crash, i.e. Windows error box saying Gretl32 has stopped working. I
am using Win8 64 bit Gretl CVS (2013-07-21).