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
Rolling Bayesian EstimationDear all, I am trying to obtain rolling "Bayesian" coefficients using a panel dataset with 50-quart…
How to aggregate variables into a single variableHi all, I am looking at sickness absence in various occupations in LFS data. The dataset contains t…
Back-transform inverse hyperbolic sine variable after survey regressionHi Stata listers, I am running an inverse hyperbolic sine regression with the survey command and ha…
Graph mirrored on x axis.Dear Statalist, I want to graph my two variables Eff...DOWN and Eff...UP across time (variable Flex…
Select cases with single observation from multiple variablesHi, I have some data in the following format: Array And what I need to do for my analysis is to se…
Subscribe to:
Post Comments (Atom)
0 Response to Loop to fill missing values
Post a Comment