Hello,
I am using a panel data set that has a unique firm id called 'firm_id'. However, this firm_id has some missing values. These missing values are all unique firms, so among the missing values no firm occurs twice. I want to fill those missing values by continuing to count from the current highest available firm_id.
(max_firm_id = the max of firm_id)
I wrote this loop:
global i = max_firm_id + 1
foreach x of varlist firm_id {
replace `x' = $i if (`x' == .)
global i = $i + 1
}
However, when I run this, all the missing values are replaced by the value of max_firm_id + 1. What I want is that only the first missing value gets the value of max_firm_id + 1, the second missing value is one higher, the third missing value is again one higher, and so on.
Related Posts with Loop to fill missing values
Survey pointer to spouse without MataI'm using the IPUMS extract of the CPS March Supplement. In their extract, the variables YEAR, SERIA…
Precision issues with rounding of a variableHello Statalist, I am using Stata 15.1 and would like to request advice regarding a precision issue…
Interpretation when dependent and independent variables are percentagesDear all, I have a problem with the interpretation of my dependent variables. My dependent variable…
Saving obs with parmest or parmbyHi all, I'm using national survey data to analyze health outcomes for particular population groups.…
Infix problem (using invalid varname)Hello, I am trying to read in fixed width data from a .txt file. I am following the documentation f…
Subscribe to:
Post Comments (Atom)
0 Response to Loop to fill missing values
Post a Comment