Yes, according to GDPR, Preamble 50: “The processing of personal data for purposes other than those for which the personal data were initially collected should be allowed only where the processing is compatible with the purposes for which the personal data were initially collected. … Further processing …for scientific purposes…should be considered to be compatible lawful processing operations.”
This is also stated in Article 5b: “...further processing for archiving purposes in the public interest, scientific or historical research purposes or statistical purposes shall, in accordance with Article 89(1), not be considered to be incompatible with the initial purposes”.