I am trying to replace missing values with values from the same column dependent on their equality from other columns:
I have different firms, from different industries & countries and from different years. Below is just a small example. I would like to replace the missing values (in the column industry or country) with the existing values in the column, if they come from the same firm.
For example, firm 123 is missing its industry in year 2. I have the industry in which the firm belongs to from the previous (or sometimes succeeding) years but do not know how to add it.
Another example: I have the firm 444 which is missing its country in year 3. I do have its country from the previous years but do not know how to transfer / copy it to the 3rd year:
--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----------.
I looked up on stata/help and on the internet. All I could find was the replace command, but it only replaced equal numbers.
I think it will be something with:
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==.
I am not sure for the country replacement, because the observations are not numbers. I think I will need to generate a new variable with numbers for the country-replacement.
Thanks a lot!