[英]how to group observations in stata
I'm a beginner with stata so this question might be easy for some of you. 我是stata的初学者,因此对于某些人来说,这个问题可能很容易。 I have a Dataset with Firmspecific data.
我有一个包含特定公司数据的数据集。 One variable is
Branche
which contains the following lines of business: Consumer
, Utilities
, Food/Beverage
, Technology
, Logistics/Transportation
, Retail
, Insurance
etc. Now I want to form groups, for example the group Consumer
which should contain Retail, Food/Beverages, Consumer
but with the command generate Consumer = Consumer Retail Food/Beverages
it doesn't work. 一个变量是
Branche
包含企业的下列行: Consumer
, Utilities
, Food/Beverage
, Technology
, Logistics/Transportation
, Retail
, Insurance
等。现在我想形成团体,例如组Consumer
应包含Retail, Food/Beverages, Consumer
但是使用命令生成Consumer = Consumer Retail Food/Beverages
它不起作用。 Does anyone know what the right command would be? 有谁知道正确的命令是什么? Thanks!
谢谢!
You can use user-written string recode command strrec
: 您可以使用用户编写的字符串重新编码命令
strrec
:
ssc install strrec
strrec Branche ("Consumer" "Retail" "Food/Beverage" = 1 "Consumer"), gen(trunk)
You will need to add additional categories as you see fit. 您将需要添加其他适当的类别。 This creates a new variable, trunk, that has labeled integer(s).
这将创建一个新的变量trunk,该变量已标记为整数。
You can refer to particular trunks like this: 您可以像这样引用特定的中继:
list if trunk == 1
list if trunk == "Consumer":trunk
The reason I used an integer with value labels rather than a string is that some of the panel data commands do not like string IDs. 我使用带有值标签而不是字符串的整数的原因是某些面板数据命令不喜欢字符串ID。 I am guessing you are headed that route.
我猜你正朝那条路走。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.