Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Retrieving data from matrix


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: Retrieving data from matrix
Date   Mon, 2 Dec 2013 17:38:43 -0500

You didn't copy Nick's code correctly: there's a space between "iter" and "`i'".

Steve

On Dec 2, 2013, at 5:32 PM, Francis, Richard N wrote:

Nick,

Thank you for your idea.

I used the following code, but now receive a syntax error (comment-out the svmat line, and the syntax error disappears):

destring gvkey, replace
egen id = group(gvkey), label
gen date1 = yq(year, fqtr)
tsset id date1, quarterly
su id, meanonly
local limit=r(max)
foreach v in k maic sic rmse DFGLS {
     g `v' = .
}
gen which = ""

forval i = 1/`limit' {
        display "Iteration of `i' of `limit"
        replace which = "`: label (id) `i''" in `i'
        dfgls fcf if id == `i' , maxlag(4) ers
		 matrix results=r(results)
		 svmat results, names(iter `i'_)
        qui foreach v in k maic sic rmse DFGLS {
               replace `v' = r(`v') in `i'
		
        }
}

What did I do wrong?

Rick Francis

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, December 02, 2013 3:01 PM
To: [email protected]
Subject: Re: st: Retrieving data from matrix

The error is coming from -svmat-. Consider that _second_ time around the loop -svmat- is trying to use the names for new variables that it used _first_ time around the loop. You must exploit the -name()- option to use different names each time around the loop. e.g.

svmat results, names(iter`i'_)
Nick
[email protected]


On 2 December 2013 21:22, Francis, Richard N <[email protected]> wrote:
> Hi Statalist members,
> 
> Have a simple program below, but receive the following error:
> 
> "new variables cannot be uniquely named or already defined"
> 
> I am using Stata13 with Windows.
> 
> The first execution of the loop works fine, then as the second loop is ending, I receive the "new variables cannot be uniquely named or already defined" error message.
> 
> Here is the code:
> 
> destring gvkey, replace
> egen id = group(gvkey), label
> gen date1 = yq(year, fqtr)
> tsset id date1, quarterly
> su id, meanonly
> local limit=r(max)
> foreach v in k maic sic rmse DFGLS {
>      g `v' = .
> }
> gen which = ""
> 
> forval i = 1/`limit' {
>         display "Iteration of `i' of `limit"
>         replace which = "`: label (id) `i''" in `i'
>         dfgls fcf if id == `i' , maxlag(4) ers
>                 matrix results=r(results)
>                 svmat results
>         qui foreach v in k maic sic rmse DFGLS {
>                replace `v' = r(`v') in `i'
> 
>         }
> }
> 
> 
> In this case, the matrix is 4x5, and the replace `v' command above creates 4 new rows.
> 
> How would I modify this to create only one new row from the matrix?
> 
> Any ideas are greatly appreciated!
> 
> Thank you for your time and expertise!
> 
> 
> Rick Francis
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index