[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Grochulski, W. Daniel" <DGrochulski@healthcore.com> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Re: SAS -> Stata |

Date |
Thu, 28 Aug 2003 10:45:21 -0400 |

add the following remarks: The SAS code we try to imitate is in fact somewhat faulty (or at least poorly designed) - the stated purpose is to generate a series of values based on equally spaced ln_time points, but this code is NOT generating what is claimed, because clearly we are NOT getting "evenly spaced points" - the last step in LN_TIME (from 500 to 501) is shorter then other steps by as much as 11% (just take a look at the SAS results). This comes out as a consequence of a poorly designed loop, where it accumulates error in the increment definition, so the required final value of 30 years (360 months) is never produced by the loop and this has to be brutally remedied by calculating point #501 separately, outside the loop. The required series can be generated by: clear set obs 501 gen ln_time = (_n - 1)*(1 + ln(360))/500 - 1 gen months = exp(ln_time) gen years = months/12 Double precision is not really necessary here (one thinks), since the original SAS code seemingly doesn't mind the rough definition of the increment involved. If one absolutely insists on reproducing (faulty) SAS results, just run: clear set obs 501 gen ln_time = (_n - 1)*(1 + ln(360))/499.9 - 1 gen months = exp(ln_time) gen years = months/12 replace ln_time = ln(360) in 501 replace months = 360 in 501 replace years = 30 in 501 which illustrates the point nicely. Daniel -----Original Message----- From: Christopher F Baum [mailto:baum@bc.edu] Sent: Thursday, August 28, 2003 6:57 AM To: statalist@hsphsun2.harvard.edu Subject: st: Re: SAS -> Stata On Thursday, August 28, 2003, at 02:33 AM, Kevin wrote: > I believe the below do-file should generate the data that SAS would > generate. The only problem I could not solve was how to get the last > observations exactly like it appeared in SAS. If you could explain > what the > below syntax does in SAS I believe I could recreate the results in > Stata. > > > > BY INC,LN_MAX; > > > > Below is the do-file. > > > > clear > > local logmax = log(360) > > local inc = ((1+`logmax')/499.9) > > local obs = 0 > > > > generate logtime = . > > > > local logmax = `logmax' + `inc' > > > > forvalues i = -1(`inc')`logmax' { > > local obs = `obs' + 1 > > qui set obs `obs' > > qui replace logtime = `i' in `obs' > > } > > > > gen months = exp(logtime) > > gen year = months/12 > > This can (and probably should) be done without an explicit loop. Loops are familiar to SAS users, but hardly appropriate in Stata's syntax: clear set obs 501 scalar logmax = log(360) g obs = _n g double inc = -1 replace inc = ((1+logmax)/499.9) in 2/l g double logtime = sum(inc) g double year = exp(logtime)/12 list in 499/l Kit * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**Re: st: SAS to Stata do instruction** - Next by Date:
**st: RE: stcox with continuously time-varying covariates only** - Previous by thread:
**st: Re: SAS -> Stata** - Next by thread:
**st: Re: merge and joinby** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |