Generally speaking, "counters", or timers in general, aren't supported that well. You can use the LoadData and SaveData functions to fudge this a bit, which is how the "Building Resources" mod adds the extraordinarily useful ability to have buildings create resources. But this has its own issues, such as the fact that it only registers a change at the start of the following turn (when the Saved data no longer matches the current data). What you're describing would not be easy.
There are a couple other ways you can fudge timers in general. The first is the Anarchy timer, which obviously has limited utility, but I've made use of it a couple different ways in my own mod. It's very useful if you need a timer that counts down automatically but which can still be tweaked along the way. Not really appropriate for what you're describing, though.
The second is that Buildings and Projects can be built multiple times in a city if the right flags are set. Projects, especially, have a simple GetProjectCount mechanism, and don't have some of the balance issues associated with a Building (like how you can't "sell" a Project like you can a building, or how buildings show up in the UI). So, all you'd need to do for this counter is to create a new Project, and have the Lua script "build" another copy of it every time you want to increment the counter. It's permanent, it's instantaneous, it's easily extracted in Lua if you want an empire-wide total on short notice, and it doesn't rely on any kind of UI-specific Serial Event to work. But I don't know if there's any kind of cap on the number involved before bad things would start to happen.