From a grammatical point of view, the way you phrased your question is a bit misleading.
We do see wordings like "worthwhile to do something", but it doesn't mean that there is a special relationship between "worthwhile" and "to do something". "worthwhile" is a simple adjective that never requires any phrase after it.
Consider these sentences:
1. It is important to study hard = To study hard is important.
2. It is worthwhile to study hard = To study hard is worthwhile.
"important" and "worthwhile" just happen to come before "to study" because of the "It is ..." pattern. "It" is a placeholder for "to study ..." in this sentence, not referring to anything independently, and it's possible to say "studying hard" instead of "to study hard", although it is considered an inferior (some say wrong) option. In short, there is no such grammar point as "worthwhile to do ..." or "worthwhile doing ..." any more than there is with "important to do" - it's just a coincidence in wording.
The word you need to know about is "worth". "worth" means something has enough value to make it profitable to do something. It is similar to "worthwhile" but more versatile in usage.
- Our country is worth fighting for. (You can't say "... worthwhile fighting for")
- The city Rio de Janeiro is worth visiting.
In these sentences, "worth" is a preposition working with "fighting" and "visiting" ("to fight" and "to visit" would be wrong).
Now this is a useful pattern worth remembering.