当前位置: 动力学知识库 > 问答 > 编程问答 >

extract - Stata related -selecting specific rows

问题描述:

I am currently working with a dataset that has information on individuals i = 1,...,N by time t = 1,...,T. I basically have a panel structure in my dataset. However, I want to select only one row of data from each individual. Specifically, I want to select only the last time period t=T for each individual i=1,...,N. How can I 'extract' this specific information from the bigger dataset?

网友答案:

In Stata [not STATA] rows are more properly called observations. You can "select" the last observation in each panel with the generic

bysort id (time) : ... if _n == _N 

as under the aegis of by:

  1. the built-in variable _n identifies observations in each panel

  2. its sibling _N is the number of observations in each panel and therefore identifies the last observation in each panel.

This is well documented: e.g. see the help and manual entries explaining the by: prefix.

分享给朋友:
您可能感兴趣的文章:
随机阅读: