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: Loop fails to replace missing values


From   Christopher Baum <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Loop fails to replace missing values
Date   Fri, 6 Dec 2013 08:42:09 +0000

<>
On Dec 5, 2013, at 7:33 AM, Richard wrote:

> 
> Have a loop with a REPLACE command which fails to update the missing values with valid numeric values.
> 
> The loop is as follows:
> 
> 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 tstat {
>      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 b = e(b)
> 		 matrix v1 = e(V)
> 		 scalar coeff = b[1,1]
> 		 scalar se1 = sqrt(v1[1,1])
> 		 scalar tstat = coeff/se1
> 		 qui foreach v in tstat {
> 				
>                replace `v' = r(`v') in `i'
> 		
>         }
> }
> 
> The -dfgls- program generates the e(b) and e(V) matrices, but I'm unsure if my use of "scalar" in this situation is correct.

As one of the original authors of -dfgls-, I would point out that it is an r-class program, not an e-class program, so it does not explicitly return e(b) and e(V). As its internals involve running a series of -regress- commands, those objects are of course defined in the process, but you should be very careful in using them. For instance, your command above

>         dfgls fcf if id == `i' , maxlag(4) ers

causes 4 regressions to be executed, but only the last -- the one pertaining to lag(1) -- is accessible. Thus, you might as well say maxlag(1), as that is the only result you will be able to access in e(b() and e(V).

Furthermore, all of the code

> 		 matrix b = e(b)
> 		 matrix v1 = e(V)
> 		 scalar coeff = b[1,1]
> 		 scalar se1 = sqrt(v1[1,1])
> 		 scalar tstat = coeff/se1

is quite unnecessary, as it merely redefines the last element of column 4 of r(results). If after running -dfgls- you -mat list r(results)- you will see that the dfgls statistics for each lag (not just the first lag) are accessible there, and can be extracted and retabulated however you wish.

In general you should only access e(b) and e(V) from an e-class program, which is guaranteed to return them.

Kit


Kit Baum
Professor of Economics and Social Work, Boston College, Chestnut Hill MA, USA
DIW Research Professor, Department of Macroeconomics, DIW Berlin, Berlin, Germany
[email protected]  |  http://ideas.repec.org/e/pba1.html


*
*   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