def lagged_values(data, target_var, features_list, window_size):
    """
    Cacluate lagged values of target variable and store results in new columns

    Parameters
    ----------
    data: data frame 
        It has columns location, date, and a column with the response variable to forecast.
        This data frame needs to be sorted by location and date columns in ascending order.
    target_var: string
        Name of the column in the data frame with the forecast target variable.
    features_list: list of strings
        Running list of feature column names
    window_size: integer
        Time window to calculate lagged values for
    
    Returns
    -------
    data: data frame 
        Original data frame with additional columns for lagged values.
    features_list: list of strings
        Running list of feature column names
    """
    for lag in range(1, window_size + 1):
        data['lag_' + str(lag)] = data.groupby('location')[target_var].shift(lag)
        features_list.append('lag_' + str(lag))
    return data, features_list