Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: SAS -> Stata


From   Christopher F Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: SAS -> Stata
Date   Thu, 28 Aug 2003 06:57:02 -0400

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/




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