I have a question about how to extract numbers and operation symbols from a string variable in Stata.
My data look as below:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str19 packing "20s*2" "10s x 3" "" "" "950gx2" "20s x 2" "20s x 2" "20s x 2" "100s" "10s" "" "20s x 2" "16s" "" "" "18s x 2" "700ml" "" "20s x 2" "500g" "" "16s" "700ml" "700ml+200ml x 2" "20ml x 6pcs" "16s" "" "525ml x 2" "700ml" "950gx2" end
What I want is the total unit of the products, for instance for "20s*2",I want to have 20*2=40; while for "700ml+200ml x 2" I want to get 1100. I don't know how to extract both the numbers and the operation symbols so that I can get the total amount of the units of the product.
I wonder if anyone has any suggestions with respect to this issue?
Thank you very much.
0 Response to How to extract numbers and operation symbols from string variables in Stata
Post a Comment