I would recommend to take a look into the online book by Rob Hyndman
https://otexts.com/fpp3/
Especially search for the concept of a tsibble (time-series table), that is a longformat data structure in the R (tidyverse) framework.
If you want to do machine learning, I can recommend the modeltime package by Matt Dancho (https://business-science.github.io/modeltime/). Traditional models (Regression models) can also be done within this framework.
First, it is necessary to separate the time and cross-sectional units. Subsequently, data entries should be made according to the relevant programming language.
To convert a time series for statistical analysis, ensure it’s stationary (using differencing or transformations), handle missing values, set a regular time interval, and properly index the time variable (e.g., using tsset in Stata or pd.to_datetime() in Python).
In Stata, to prepare a time series for analysis, use xtset or tsset to define the panel or time variable, check for stationarity with tests like dfuller or pptest, handle missing data with tsfill, and create lags using gen lag_var = L.var_name.