This may sound like a stupid question, but is it possilbe to create a string object e..g string _X (which works) and update the string within the program in a for loop rather than manually opening string and typing it in?
Thanks in advance
string object program fill
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Re: string object program fill
This may sound like a stupid question, but is it possilbe to create a string object e..g string _X (which works) and update the string within the program in a for loop rather than manually opening string and typing it in?
Thanks in advance
Sorry that was late at night, just realised that this question doesn#t make sense.
What I'm trying to do is to create a string object and update that string object within a program. I would want to use it in a loop.
1) For example, look at the following working simple part of the code
run program Y _X 4
pogram is an external program producing correlation matrixes for regression analysis. The way it is programmed, the first argument is the dependent variable Y, the second one has to be a string object which is listing the explanatory variables and the third and last argument is the number of lags (in this case 4).
The Program runs beautifully, but I now want to run it en masse, ie
2) for a lot of variables. This is how I set it up:
' _countries is a string object containing 3 letter country codes, ie. the loop should rund over these countries
for %ccode {_countries}
run pogram D_{%ccode} _X 4
next
Obviously this only runs the loop over the dependent variable but the explanatory variable within the string object _X is restricted to its predefinition. The obvious solution would be (given that the structure of the explanatory variables is always I_*_{%ccode} where {%ccode} is the three letter country code) the following
for %ccode {_countries}
for %x I_*_{%ccode}
run pogram D_{%ccode} {%x} 4
next
next
or simply
for %ccode {_countries}
run pogram D_{%ccode} I_*_{%ccode} 4
next
The Problem I have is that the program running the correlation matrixes requries the second argument to be a string object. Hence two things I thought of where
1) write a loop to creates string objects for every country ie. let there be string _X_??? with ??? being the three letter country code and the string contains the variable names. HOwever, I was not able to create a string object with the command string _X and update that string within that loop. So my question is, is that even possible or do I have to manually update string objects via creating that object and typing it in.
2) from my understanding a string object simply is a list of series names wich when put into a loop will run this loop with the list of series successively. My problem is that the list of variables is the same only with a different ??? at the end for the country code specification. I could now go and manully create strings for every country e.g. _X_USA which will contain x1_USA x2_USA x3_USA....as variables/ seriesnames. But this is inefficient, especially when you want to add variables later to each regression per country ie that will require to go into each country specific string object and change it. how can I thus create string objects in a loop while using the string {%ccode} that will create country specfic explanatory variables with the structure I_*_{%ccode} ?
Thanks in advance
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: string object program fill
Code: Select all
string a = %x
Re: string object program fill
Thanks Gareth for the heads up with run vs execute.
As for the string object fill, I have done what you suggested before and get following failure message: "series assigned to string".
Please have a look at this example:
I have explanatory variables (exchange rates) in the structure rx_??? where ??? is the three letter country code. I now want to create a string object called _rx which is filled with all rx_* in a loop. This is what I wrote.
or directly:
Both produce the error "series assigned to string". Where am I going wrong?
The point is that the first string object used: _countries works like a charm, but I manually pasted the list of country codes into the string objects ("update string").
I want to do this in a loop in the program. Is that not possible?
Thanks in advance
As for the string object fill, I have done what you suggested before and get following failure message: "series assigned to string".
Please have a look at this example:
I have explanatory variables (exchange rates) in the structure rx_??? where ??? is the three letter country code. I now want to create a string object called _rx which is filled with all rx_* in a loop. This is what I wrote.
Code: Select all
for %ccode {_countries}
%rx = rx_{%ccode}
string _rx = %rx
next
Code: Select all
for %ccode {_countries}
string _rx = rx_{%ccode}
next
Both produce the error "series assigned to string". Where am I going wrong?
The point is that the first string object used: _countries works like a charm, but I manually pasted the list of country codes into the string objects ("update string").
I want to do this in a loop in the program. Is that not possible?
Thanks in advance
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: string object program fill
I don't understand what you're trying to do with either of those loops.
String objects and string variables (% variables) are identical. They both contain strings. i.e. they contain quoted text. In neither of those loops are you assigning quoted text to a string variable, or string object.
String objects and string variables (% variables) are identical. They both contain strings. i.e. they contain quoted text. In neither of those loops are you assigning quoted text to a string variable, or string object.
Re: string object program fill
Just realized that I left out the quotation marks...moment of glory :?I don't understand what you're trying to do with either of those loops.
String objects and string variables (% variables) are identical. They both contain strings. i.e. they contain quoted text. In neither of those loops are you assigning quoted text to a string variable, or string object.
Got it to work this way:
_countries being predefined string object with 3 letter code and the string _x_??? now contains the country specific exchange rate series rx_???
Code: Select all
for %ccode {_countries}
string _x_{%ccode} = ""
_x_{%ccode}= "rx_"+ %ccode
next
Is it possible to have multiple arguments in line 3 of the code, ie fill the string object _x_{%ccode} with multiple variables "1"+%ccode "2"+%ccode etc. not sure how to differntiate between the arguments/variables
The following didn't work:
Code: Select all
for %ccode {_countries}
string _x_{%ccode} = ""
_x_{%ccode}= "rx_"+ %ccode "pcpi_"+ %ccode "I_"+ %ccode
next
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: string object program fill
You missed a +.
Code: Select all
for %ccode {_countries}
string _x_{%ccode} = ""
_x_{%ccode}= "rx_"+ %ccode + "pcpi_"+ %ccode "I_"+ %ccode
next
Who is online
Users browsing this forum: No registered users and 1 guest
