Bookmark and Share

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

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

st: Loop fails to replace missing values

From   "Francis, Richard N" <>
To   "" <>
Subject   st: Loop fails to replace missing values
Date   Wed, 4 Dec 2013 14:07:39 +0000

Hi Statalist users,

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.

Any help is greatly appreciated. 

Thank you!


*   For searches and help try:

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