Optimal number of lags before applying the Augmented Dickey-Fuller in STATA

#1
As a part of my master thesis, which is a study of the relationship between oil prices and the performance of alternative energy shares, I have to perform an augmented Dickey-Fuller test to see whether my data set is stationary.

For simplicity reasons I have only included two data series in addition to the dates (the attachments displays an excerpt of the data series and the entire data series graphically), and the ultimate goal is to find out how ln_avgoil (x) affects the ln_nex(y). However I have still a long way to go before arriving at this stage.

According to my knowledge the best procedure is to find the optimal number of lags before applying this test on the different time series. My question to you is how I find this (how do I write the code that solves this problem)? In addition I wonder if this test have to be conducted on all dependent and independent variables?