Dear all,
This is not a statistical question (I apologize) but one for a function.
I have data for origin and destination (data provided below); I would like to generate a variable based on a function, e.g.
Such that y will be generated for each origin to all the dest but will not generate for the origin, e.g. for AFG, I would like generate y for all the destinations except AFG itself. Also, while the values for var_d will be for all the destinations, the value for var_o will be only for the origin (in this case AFG).
I realize that I have to use foreach but I am having a difficult time with the condition. I hope I have provided enough information, any help will be highly appreciated. Thanks!
Sincerely,
Chiara
This is not a statistical question (I apologize) but one for a function.
I have data for origin and destination (data provided below); I would like to generate a variable based on a function, e.g.
Code:
gen y= a*var_o + b*var_d
I realize that I have to use foreach but I am having a difficult time with the condition. I hope I have provided enough information, any help will be highly appreciated. Thanks!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3(origin dest) float(var_o var_d a b) "AFG" "AFG" 14.3 14.3 .4 1.2 "AGO" "AGO" 14.7 14.7 .4 1.2 "ALB" "ALB" 15.4 15.4 .4 1.2 "AND" "AND" 16.4 16.4 .4 1.2 "ARE" "ARE" 23.9 23.9 .4 1.2 "ARG" "ARG" 24.4 24.4 .4 1.2 "BDI" "AUS" 25 25 .4 1.2 "BEN" "AUT" 25.5 25.5 .4 1.2 "BFA" "BDI" 15.9 15.9 .4 1.2 "BGD" "BEN" 16.5 16.5 .4 1.2 "BGR" "BFA" 17.2 17.2 .4 1.2 end
Chiara
Comment