Replacing observations with a previous set observation

ぐ巨炮叔叔 提交于 2019-12-11 15:43:29

问题


I have three columns. One identifies the observations by F. The other column orders each observation within the same F, called T. The third column is a numerical value, called Q. I'd like all my values for Q greater than a certain value of T to be replaced by the values at a fixed T, within the same F. For example, I'd like all values of Q within the same F that have T > 6 to be equal to whatever value Q has for that F has for T = 6. If an F has a Q value of 40 at T=6 and a Q value of 50 at T=7, I want that Q at T=7 to say 40 as well.


回答1:


This might not be the correct way of solving this, but it did the trick. If anyone has a better solution, please help me out.

xtset F T
gen Q_fixed = Q
replace Q_fixed = . if T > 6
replace Q_fixed = L.Q_fixed if Q_fixed == . 


来源:https://stackoverflow.com/questions/46638497/replacing-observations-with-a-previous-set-observation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!