问题
I have a basic question about Stata. I have programming experience in R but I've started a new job where Stata is the main language. I'm currently diving into Stata on my own and sometimes it's hard to understand how to do simple things.
I've trying to get 5 random numbers between 3 and 50 but without success.
In R, any of these would work:
floor(runif(5, min=3, max=50))
16 39 11 11 5 # output
sample(3:50, 5, replace=TRUE)
28 13 5 36 19 # output
But I'm not sure how to do this in Stata, specifically how to return random numbers within the desired range (3:50). Any pointers would be appreciated. I found the runiform()
function but I don't think I can get the same output.
回答1:
Is this what you want?
set obs 5
generate rnum = runiform(3, 50)
You are basically creating a dataset first and then generating a variable with the desired properties.
来源:https://stackoverflow.com/questions/48441167/whats-the-equivalent-of-r-sample-function-in-stata