如何在面板数据中替换缺失值?

发布于 2025-02-05 10:28:56 字数 124 浏览 3 评论 0原文

我正在研究每周的收入数据,在该数据中,我将数据定义为学前收入的数据和流行后收益数据。现在,对于某些人来说,我想用他们的大流行前的收入来代替大流行时期的一些缺少价值。但是,我正在为此面板数据编码苦苦挣扎。我希望有人可以帮助我。提前致谢。

I am looking into weekly earnings data, where I have defined my data as pre-pandemic earning data and post-pandemic earning data. Now for some individuals, I have some missing values for the post-pandemic period which I want to replace with their pre-pandemic earnings. However, I am struggling with the coding for this panel data. I was hoping someone could help me with. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够爱げ你 2025-02-12 10:28:56

如果您共享示例数据(请参阅dataEx),或者至少列出您拥有的变量总是更容易的。因此,下面的示例很可能需要进行编辑。

* Sort the data by individual id and the time unit
* that indicates if this the obs is pre or post pandemic
sort id time

* This replaces the earnings value with a missing value if the
* id var is the same as on the next row AND the earnings var
* on is missing on the next row
replace earnings = . if id == id[_n+1] & missing(earnings[_n+1])

这假设所有个人确实在每个时间段内都表示,并且您的数据集中有一个唯一的ID变量(ID)。

It is always easier if you share example data (see dataex) or at least list what variables you have. The example below will therefore most likely need to be edited.

* Sort the data by individual id and the time unit
* that indicates if this the obs is pre or post pandemic
sort id time

* This replaces the earnings value with a missing value if the
* id var is the same as on the next row AND the earnings var
* on is missing on the next row
replace earnings = . if id == id[_n+1] & missing(earnings[_n+1])

This assumes that all individuals are indeed represented in each time period and that you have a unique id variable (id) in your data set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文