Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: re: Re: forvalues, panel data


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: re: Re: forvalues, panel data
Date   Sun, 3 Oct 2010 17:50:52 +0100

Well, the original poster had 11 values. I think Kit's right that his method is superior for large problems or as a systematic approach for doing this repeatedly, but my advice was in the context of a very small specific problem. And anyone who doesn't check key coefficients very carefully deserves to get lousy results. 

Nick 
n.j.cox@durham.ac.uk 

Christopher Baum

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


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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index