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: RE: re: Re: forvalues, panel data

From   "Biljana Dlab" <[email protected]>
To   <[email protected]>
Subject   st: RE: re: Re: forvalues, panel data
Date   Sat, 2 Oct 2010 20:40:47 +0200

Thanks a lot guys :o)

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Christopher
Sent: 02 October 2010 03:47
To: [email protected]
Subject: st: re: Re: forvalues, panel data

Nick said

I certainly agree with Kit that a -merge- with a file with coefficients
is another way to do it, and one worth knowing about. But I can't see
it's less error-prone. Either way, someone has to type the numbers in or
read them from somewhere else and there is equal scope for error so far
as I can see. 

Nick Cox 

> Your -forvalues- scaffolding is completely redundant, and in fact
causes the same changes to be executed 11 times. But your problem does
call for a loop over a varlist.
> foreach v of var <whatever> {
>        gen d`v' = .
>        replace d`v' = `v' if fyear == 1980
>        replace d`v' = `v' * 0.967059 if fyear == 1981
>        <etc>

I respectfully disagree with Nick's assessment of relative risk. When
one types (or copy/pastes) a large number of statements such as

replace d`v' = `v' * 0.967059 if fyear == 1981

it takes some concentration to pick up the next number from the deflator
series AND attach it to the correct year. This requires a lot of typing,
or copy/pasting, and most would agree that after you copy/paste the same
line 20 times and then make two manual edits on each line, Pr[accuracy]
< 1. Putting those values in a file will, for instance, allow -merge- to
squawk if you make the mistake of repeating a year, or leaving a year
out, of the auxiliary file; that will either cause a m:1 merge to fail
or leave some years in the panel data unmatched, either of which can
readily be caught. You can also tsset and -tsline deflator- on the
auxiliary file, before merging, to see whether the values are reasonably
smooth, as they should be for a deflator. 

Furthermore, in cases where there might be alternative price deflator
series (e.g. PCE deflator vs. CPI) to be considered, it is easy to add
them to the auxiliary file, and just change one line that does the
deflation. The explicit 'replace .. if' method would require manual
adjustment for every data value of the alternate series.


Kit Baum   |   Boston College Economics & DIW Berlin   |
                              An Introduction to Stata Programming  |
   An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

*   For searches and help try:

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