I have a survey data set (panel). In the dataset, I have a variable in which few numbers are wrongly entered. For example, if an establishment has started in a particular year (starting_year), the starting_year is not supposed to vary. In few of the years, the starting_year has been entered as 0. I have used the following commands to replace the wrongly entered values with the correct values but I am not able to replace it:
egen tag = tag(panel_id starting_year)
egen ndistinct = total(tag), by(panel_id)
bysort panel_id (starting_year) : replace starting_year = starting_year[_N] if missing(inityr) & ndistinct == 1
STATA result
(0 real changes made)
An analogous data file is attached. I would really appreciate the help.
Related Posts with Help in editing (replacing some values) a variable in panel data
How to replace the newline/nextline character in a column with space characterHello! I understand that subinstr can be used to replace a substring in a column https://www.stata.…
How to calculate date_month variable from Date (dmy) and day of year (doy)Hi, I have been wondering if there is a way to present average annual statistics from time-series d…
Adding month observations to year level dataHi, I am working with the following variables: Code: * Example generated by -dataex-. For more info…
Log function within loopsHello Stata experts, I am trying to perform a log function within loops, but it gives me errors tha…
Combine a bunch of dummy variables into a multinomial/categoricalIt is trivial to convert a categorical variable into a bunch of dummy variables. I would like to do…
Subscribe to:
Post Comments (Atom)
0 Response to Help in editing (replacing some values) a variable in panel data
Post a Comment