Accessing max/min of a list of numbers stored in numlist / local

434 views Asked by At

Is there a way to access the maximum and minimum values stored in a numlist or local using something like min() and max() in Stata? I want to archive roughly something similar to this:

local test 5 10 25 50
local max_test = max(`test')
local min_test = min(`test')

foreach i in `test'{
qui gen x_`i' = `i'
}

reg y x_`min_test ' - x_`max_test '
1

There are 1 answers

0
Nick Cox On BEST ANSWER

The help for max() tells you that it accepts comma-separated arguments, so this will work:

local test 5 10 25 50
local test : subinstr local test " " ",", all 
local max_test = max(`test')

Naturally, you could put the commas in at the outset. Same story for the minimum.