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
Graph: Large gap between xlabel and legendHi I am trying to make a graph similar to this one: Code: sysuse auto, clear gen xvar = _n keep if…
Error in expressionHello, I am created a local variable `tif' which loops over around 45 terms (string). local tif "0…
net reclassification index (NRI) and integrated discrimination index (IDI)*computing confidence intervalsHi All, I am having difficulties obtaining 95% CI's from the NRI and IDI command in stata. I have p…
Problem with two merged datasets: time series and panel data relatedHi all, I am new to statalist, and relatively new to stata, so please bear that in mind when replyin…
Gen new variableHi! I want to make a measure for institutional trust. x1 = trust in judicial system x2 = trust in …
Subscribe to:
Post Comments (Atom)
0 Response to Loop to fill missing values
Post a Comment