If you're downloading gretl from this site you can be confident that the installer contains no malware. However, Apple's security measures may block installing and/or running gretl. You shouldn't have a security problem with installing a gretl release package, since these are both code-signed and "notarized", but gretl snapshots are not notarized.
In any case, what you have to do depends on the version of macOS you're running. If it's older than Catalina (10.15) then the discussion (with screenshots) at the rampagedev blog should tell you what you need to know. If it's Catalina or higher then please read the following step-by-step guide. The name of the gretl package and the appearance of the dialogs on your system may differ from what's shown below, but the general idea should be the same.
Open System Preferences and navigate to "Security & privacy". Select the General tab. We'll come back to this window shortly.
Double-click the gretl .pkg file. You'll get a message saying that the file "can't be opened because Apple cannot check it ...". Click OK to close the window.
In the tab mentioned in item 1 you'll see a message with a button Open Anyway: click that button.
Double-click the gretl pkg file again. Now you'll get the same window as in item 2, but with two buttons: Open and Cancel. Click Open and gretl will be installed.
There's a further security issue with Catalina and higher: after installation of gretl, how do you allow the program to access files on your Desktop and other locations? Again, you do this via the "Security & privacy" item under System Preferences; see Apple's access control page.