How to take the 1st difference in Gauss?

Hello,
I am performing a panel data analysis with a dataset, I am performing unit root tests, but I need the 1st difference in a unit root test analysis.

How can I take the first difference and include it in the analysis?
Thank you very much.

1 Answer



0



GAUSS version 25 which is coming out this month, has a new built in function to compute differences of panel data.

Here is how you can do it now:

Let's say you have a dataframe that looks like this that is called df:

 Country     Year lgaspcar  lrpmg
 AUSTRIA     1960 4.173244 -0.3345476
 AUSTRIA     1961 4.100989 -0.3513276
 AUSTRIA     1962 4.073177 -0.3795177
 AUSTRIA     1963 4.059509 -0.4142514
 BELGIUM     1960 4.164016 -0.1657096
 BELGIUM     1961 4.124356 -0.171731
 BELGIUM     1962 4.075962 -0.2222914
 BELGIUM     1963 4.001266 -0.2504623

This code will create the first difference:

unique_ids = unique(df[.,id]);

// Find the first row of each id
id_idx = indnv(unique_ids, df[.,"Country"]) | (rows(df) + 1);

// Create a new dataframe with the same id's
// and dates, but missing values for the data
df_diff = df;
df_diff[.,3:4] = miss();

for i(1, rows(id_idx)-1, 1);
    // find the first and last rows of the i'th id
    start_ = id_idx[i];
    end_ = id_idx[i+1]-1;

    // Pull out the data for the i'th id
    diff_tmp = df[start_:end_,3:4];

    // Compute and assign the first difference
    df_diff[start_+1:end_,3:4] = trimr(diff_tmp, 1, 0)-trimr(diff_tmp, 0, 1);
endfor;

Which will equal:

 Country     Year   lgaspcar   lrpmg
 AUSTRIA     1960        .        .
 AUSTRIA     1961 -0.07225509 -0.01678
 AUSTRIA     1962 -0.02781255 -0.02819008
 AUSTRIA     1963 -0.01366743 -0.0347337
 BELGIUM     1960        .        .
 BELGIUM     1961 -0.03966033 -0.006021372
 BELGIUM     1962 -0.04839395 -0.05056039
 BELGIUM     1963 -0.07469562 -0.02817088

admin

47

Your Answer

1 Answer

0

GAUSS version 25 which is coming out this month, has a new built in function to compute differences of panel data.

Here is how you can do it now:

Let's say you have a dataframe that looks like this that is called df:

 Country     Year lgaspcar  lrpmg
 AUSTRIA     1960 4.173244 -0.3345476
 AUSTRIA     1961 4.100989 -0.3513276
 AUSTRIA     1962 4.073177 -0.3795177
 AUSTRIA     1963 4.059509 -0.4142514
 BELGIUM     1960 4.164016 -0.1657096
 BELGIUM     1961 4.124356 -0.171731
 BELGIUM     1962 4.075962 -0.2222914
 BELGIUM     1963 4.001266 -0.2504623

This code will create the first difference:

unique_ids = unique(df[.,id]);

// Find the first row of each id
id_idx = indnv(unique_ids, df[.,"Country"]) | (rows(df) + 1);

// Create a new dataframe with the same id's
// and dates, but missing values for the data
df_diff = df;
df_diff[.,3:4] = miss();

for i(1, rows(id_idx)-1, 1);
    // find the first and last rows of the i'th id
    start_ = id_idx[i];
    end_ = id_idx[i+1]-1;

    // Pull out the data for the i'th id
    diff_tmp = df[start_:end_,3:4];

    // Compute and assign the first difference
    df_diff[start_+1:end_,3:4] = trimr(diff_tmp, 1, 0)-trimr(diff_tmp, 0, 1);
endfor;

Which will equal:

 Country     Year   lgaspcar   lrpmg
 AUSTRIA     1960        .        .
 AUSTRIA     1961 -0.07225509 -0.01678
 AUSTRIA     1962 -0.02781255 -0.02819008
 AUSTRIA     1963 -0.01366743 -0.0347337
 BELGIUM     1960        .        .
 BELGIUM     1961 -0.03966033 -0.006021372
 BELGIUM     1962 -0.04839395 -0.05056039
 BELGIUM     1963 -0.07469562 -0.02817088


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.