同时生成和排序变量 [英] Generating and ordering a variable simultaneously

查看:80
本文介绍了同时生成和排序变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想避免对数据进行重新排序,以将生成的变量放在第一列中:

I would like to avoid re-ordering the data to place the generated variable in the first column:

sysuse auto, clear
gen random = runiform()
order random

是否可能生成一个变量并同时排序吗?

Is it possible to generate a variable and at the same time order it?

这个想法是当我在编辑器中浏览数据时能够直接观察生成的变量,当我有多个变量时,这并不容易。

The idea is to be able to directly observe the generated variable when I browse the data in the editor, which is not easy when I have several variables.

推荐答案

您可以使用 before()选项:

sysuse auto, clear
generate random = runiform(), before(make)

您还可以按以下步骤进一步自动化该过程:

You can also further automate this process as follows:

unab var : *
gettoken var : var

generate random = runiform(), before(`var')

这篇关于同时生成和排序变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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