Stata中R样本函数的等价物是什么 [英] What's the equivalent of R sample function in Stata

查看:68
本文介绍了Stata中R样本函数的等价物是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 Stata 的基本问题.我有 R 编程经验,但我开始了一份新工作,其中 Stata 是主要语言.我目前正在自己​​深入研究 Stata,有时很难理解如何做简单的事情.

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.

我试图获得 3 到 50 之间的 5 个随机数,但没有成功.

I've trying to get 5 random numbers between 3 and 50 but without success.

在 R 中,任何这些都可以工作:

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

但我不确定如何在 Stata 中执行此操作,特别是如何返回所需范围(3:50)内的随机数.任何指针将不胜感激.我找到了 runiform() 函数,但我认为我无法获得相同的输出.

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.

推荐答案

这是您想要的吗?

set obs 5
generate rnum = runiform(3, 50)

您基本上是先创建数据集,然后生成具有所需属性的变量.

You are basically creating a dataset first and then generating a variable with the desired properties.

这篇关于Stata中R样本函数的等价物是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆