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
Consolidating two line graphs and editing X and Y axis labels and title on Line GraphHi, I am working with a dataset of 14 observations, and I am trying to make a line graph using these…
how do I get an overall p value for independent factor variables in linear regressionHi, I am running a backwards stepwise linear model with factor and continuous predictor variables. M…
testing difference between coefficients in different equationsI would like to run the following regressions: xtreg a x y z i.mth_seq, fe vce(robust) *equation 1 …
Need advice on recoding categorical variables into continuous variables and vice versaI am new to data analysis and Stata, so I apologise if I have not explained this very well. I have …
Monthly Unemployment Rate Calculation for Two Groups of StatesHi, I am working on a project in which I have data from the CPS. I also have data that tells me when…
Subscribe to:
Post Comments (Atom)
0 Response to Loop to fill missing values
Post a Comment