23 lines
611 B
Plaintext
23 lines
611 B
Plaintext
program define maprange
|
|
version 15.1
|
|
syntax varname(numeric) [if] [in], ///
|
|
from(numlist min=2 max=2) to(numlist min=2 max=2) ///
|
|
GENerate(name) [REPLACE]
|
|
tempname a b c d h
|
|
sca `a'=`:word 1 of `from''
|
|
sca `b'=`:word 2 of `from''
|
|
sca `c'=`:word 1 of `to''
|
|
sca `d'=`:word 2 of `to''
|
|
sca `h'=(`d'-`c')/(`b'-`a')
|
|
cap confirm variable `generate'
|
|
if "`replace'"=="replace" & !_rc {
|
|
qui replace `generate'=(`varlist'-`a')*`h'+`c' `if' `in'
|
|
}
|
|
else {
|
|
if "`replace'"=="replace" {
|
|
di in gr `"(note: variable `generate' not found)"'
|
|
}
|
|
qui gen `generate'=(`varlist'-`a')*`h'+`c' `if' `in'
|
|
}
|
|
end
|