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

st: Re: SAS -> Stata

From   Christopher F Baum <>
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.


Below is the do-file.


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:

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


* For searches and help try:

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