But, I have heard of companies that do carpet dyeing. Think about that.
My suggestion is this and only this if the stain is not in or on a traffic aisle.
Cut the area out into a nice square. The bigger the square the better it will stay down. Then go to a closet or better still your carpet dealer that has the same carpet. If you cannot find the same carpet, which is usually the problem, then go to the closet and cut out the same size square.
On the cut out area, apply a good quality carpet tape all around the cut out area then lay the new piece in the hole and this should work well. Today's carpet tape is great and does work. There are the pressure tape for carpets and the kind that you use a warm iron on to melt the glue on the edges. Follow the instructions if you use the iron method.
Now, if this happened in a small room, consider, if you can find the exact carpet, just lay down new carpet and have a neat line cut meeting the old carpet at the doorway.
Good luck, but besides dyeing, you will not be able to change the appearance of the spot.