Hello, I am trying to replace a missing value with the average several other responses. I am running the code below which does not end up replacing the missing values in pt_bbq6_rc_mis for some reason. I realize this is a simple coding error somewhere but I would sure appreciate some assistance. Thanks!
Jake
Code:
*
capture drop pt_bbq6_rc_mis // replacing missing value with average or recoded response
gen pt_bbq6_rc_mis = pt_bbq6_rc
replace pt_bbq6_rc_mis = (pt_bbq1_rc + pt_bbq2_rc + pt_bbq3_rc + pt_bbq6_rc + ///
pt_bbq8_rc + pt_bbq10_rc + pt_bbq12_rc + pt_bbq12_rc + pt_bbq14_rc ) / 8 if pt_bbq6_rc_mis == .
order pt_bbq6_rc_mis, before(pt_bbq6_rc)
the missing values on pt_bbq6_rc_mis are not being replaced. see daetex below for record_id 101 as an example.
clear
input int record_id float(pt_bbq1_rc pt_bbq2_rc pt_bbq3_rc pt_bbq4_rc pt_bbq5_rc pt_bbq6_rc_mis pt_bbq6_rc pt_bbq7_rc pt_bbq8_rc pt_bbq9_rc pt_bbq10_rc pt_bbq11_rc pt_bbq12_rc pt_bbq13_rc_mis pt_bbq13_rc pt_bbq14_rc)
51 4 5 1 5 1 3 3 5 5 3 3 5 1 1 1 1
52 5 5 5 5 2 3 3 5 5 2 5 3 5 2 2 3
54 4 5 3 4 1 5 5 5 5 2 5 5 3 4 4 2
55 5 3 2 5 2 2 2 5 5 2 4 5 1 2 2 2
56 3 4 2 4 1 5 5 4 4 4 4 3 2 2 2 2
58 5 4 3 4 3 2 2 3 3 3 2 3 3 3 3 2
59 1 2 1 3 1 1 1 5 5 1 3 3 3 2 2 3
61 4 5 1 4 2 2 2 5 3 2 5 5 4 3 3 3
63 5 5 5 5 1 3 3 5 5 3 3 4 3 2 2 3
67 5 3 5 5 3 2 2 5 5 3 3 5 3 3 3 3
69 4 4 4 4 2 3 3 4 5 3 3 4 3 4 4 3
71 4 5 4 4 2 2 2 3 5 3 4 4 3 3 3 4
72 3 3 2 2 3 2 2 5 5 2 2 5 2 3 3 2
73 3 1 1 3 1 1 1 2 1 4 1 2 1 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 2
112 4 4 4 4 2 2 2 3 2 3 3 4 4 2 2 3
113 4 1 5 5 2 1 1 4 2 4 4 5 4 4 4 3
114 2 2 2 2 4 3 3 5 5 3 4 2 2 4 4 2
116 4 3 4 4 2 4 4 3 4 3 3 4 3 2 2 2
end
[/CODE]
Related Posts with Replacing missing value with average of selected responses
Type of correlation used by factorHi, I've done a factor analysis using the default settings for the factor command: factor item1-item…
Creating Dummy VariableDear Statalist Experts I need to create a dummy variable from the following variable "A" with top a…
matching counties based on first two digits for finding similar stateHello, I have a data which shows distance between all counties from another county. This includes a…
Export dataset to LaTeXDear Stata Users, I have a dataset below. I want to export the data to the latex as the following t…
Replication code for Stata 14 and Stata16 producing different resultsI ran into a problem where a data replicator could not replicate an item response variable using the…
Subscribe to:
Post Comments (Atom)
0 Response to Replacing missing value with average of selected responses
Post a Comment