0

我想做这样的事情:

ds, has(type numeric)
    foreach var in `r(varlist)' {
    gen `var' = `var' - `var'[_n-1]
}

我想简单地命名新变量d+oldname

我怎样才能把这两个愿望结合起来?

4

1 回答 1

1

我认为您正在寻找的内容可能类似于以下内容:

sysuse auto, clear

ds, has(type numeric)

foreach var in `r(varlist)' {
    quietly generate d`var' = `var' - `var'[_n-1]           
    display ""
    display "`var'"
    display "d`var'"
}

这将产生:

price
dprice

mpg
dmpg

rep78
drep78

headroom
dheadroom

trunk
dtrunk

weight
dweight

length
dlength

turn
dturn

displacement
ddisplacement

gear_ratio
dgear_ratio

foreign
dforeign
于 2018-06-01T11:51:01.687 回答