Try cleaning the mass airflow sensor, the throttle body, EGR valve, and the idle air control valve. Each of these items requires a different cleaning compound; so be sure that the work is done by someone who is experienced at this, and who recognizes the need to use these specialized cleaning products.
Some Japanese cars have ignition switches which tend to burn their contacts and develop excessive internal resistance over time. So I would suggest, with the engine idling, testing the voltage between the battery lead of the ignition coil and ground, and comparing this reading to the voltage between the two battery terminals. The voltage at the battery should be from 13.5-14.5 volts (with no lights, A/C, fans, or electrical accessories running). If the voltage at the battery is below 13.5 volts; the alternator should be tested for bad diodes and full output by a shop that uses an oscilloscope to test alternators. (this test instrument looks like a heart monitor or TV set) And the voltage at the coil should be at least 13.2 volts, as well as being no more than 0.5 volts below the reading at the battery. If there is more than 0.5 volts difference between the voltage at the coil and the voltage at the battery; the ignition switch should be replaced.
I would also suggest, from over 40 years of experience in custom tuning and correcting performance issues which do not respond to normal maintenance, that certain engine designs (among which most Subarus are definitely classic examples) tend to be extremely critical about the choice of spark plug brands. There are only a few spark plug brands and models which perform consistently well in the Subaru H-4 motor; and the original equipment NGKs are NOT one of them. The only spark plug brands I would recommend for this motor are either E3, Bosch, or Champion. My preference would be the E3 # E3.64. This plug has a non adjustable gap. (Sold by Checker, Shucks, Kragen, O'Reilly, and Murray Auto parts stores, and by Summit Racing online.) My second choice would be Bosch Super Plus # 7956 (with the gap set to .044"). My third choice would be Champion Truck plug # 4430 (with the gap set to .044").
If this is done right; I think you'll be pleased with the results.
If you decide to respond again about this issue, please do so by posting your response here, underneath the existing responses; by clicking the "answer this question" button (You can do so even after a question has been closed). But if you respond to an existing topic by opening a new question, it will promptly be deleted; and neither you nor I will benefit from that.