I am trying to combine two observations in my dataset by replacing the value of a variable (tradevalue) for an observation (reporteriso == "FRA") by the sum of itself and one more observation of the same variable (reporteriso == "REU"). I need to do this grouped by years and tradeflows (i.e. do the replacement for each year and for each direction of tradeflows). I have tried
bysort year tradeflowcode: replace tradevalue_rep_part = tradevalue_rep_part[reporteriso == "FRA"] + tradevalue_rep_part[reporteriso == "REU"] if reporteriso == "FRA"I notice that reporteriso == "FRA" returns a boolean, where I would actually need a function returning the index for which this boolean is TRUE.
Which function could I use there and will this type of approaching the problem work with Stata?
Thank you!
0 Response to Replacing observations by sum of other observations (same variable)
Post a Comment