Fra*_*anz 1 replace if-statement missing-data stata
我试图用相同列中的值替换缺少值,取决于它们与其他列的相等性:
我有不同的公司,来自不同的行业和国家,不同年份.以下只是一个小例子.如果它们来自同一家公司,我想用列中的现有值替换缺失值(在列行业或国家/地区).
例如,123公司在第2年失去了它的行业.我拥有该公司所属的行业,从前几年(或有时候成功),但不知道如何添加它.
另一个例子:我有公司444在第3年错过了这个国家.我确实拥有前几年的国家,但不知道如何将其转移/复制到第3年:
--firm--year--industry--country
--123----1-------1---------usa
--123----2-------1---------usa
--123----3--------.--------usa
--333----1-------2---------usa
--333----2--------.---------usa
--444---1---------.----------fr
--444---2---------2---------fr
--444---3---------2----------.
Run Code Online (Sandbox Code Playgroud)
我查看了stata/help和互联网.我只能找到替换命令,但它只替换了相同的数字.
我认为这将是:
replace industry=(problaby something dependant of the firm (and maybe year)) if industry==.
replace country=(problaby something dependant of the firm (and maybe year)) if country==.
Run Code Online (Sandbox Code Playgroud)
我不确定国家的替代,因为观察不是数字.我想我需要为国家替换生成一个带有数字的新变量.
非常感谢!