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   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Retrieving data from matrix
Date   Tue, 3 Dec 2013 01:05:52 +0000

Transpose the matrix before -svmat-.
Nick
[email protected]


On 2 December 2013 22:48, Francis, Richard N <[email protected]> wrote:
> Nick,
>
> If the code below is creating new columns for each pass through the loop, how would I modify the code to create new ROWS instead?
>
> 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'
>
>          }
> }
>
> Thank you for all you do!
>
> 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