Importing data from Excel (.xlsx) to Gauss

Hello,
I have data on over 40 countries from 1989-2012 and 8 variables in excel spreadsheet.How can I import it to Gauss? I have red some examples but my understanding, which I think is wrong, is that observations on each variable are imported separately (for instance X, Y, Z data for all the countries and time-period are imported individually so that we can have X.dat; Y.dat; and Z.dat).Once I have the complete dataset in Gauss, I would like to apply my analysis to the full sample as well as the sub-groups.
NB: I just started learning Gauss by myself and I appreciate if you can give me tips on how to master it ASAP.
Much regards,
Solantoti

1 Answer



0



You can load the columns in as separate GAUSS variables, or as a matrix. For example, if we have an Excel spreadsheet that looks like this:

Year     X     Y     Z
1989   3.2   1.1   2.5
1990   2.8   0.9   1.8
1991   4.1   1.2   0.7
1992   2.9   0.7   0.5

where the cell A1 contains Year, B1 contains X, C1 contains Y, B2 contains 3.2, C2 contains 1.1, etc. Let's further suppose that this data is on the first sheet of an Excel file named german_data.xlsx. You can create one GAUSS matrix named germany that contains the data from X, Y and Z like this:

fname = "german_data.xlsx";
range = "B2:D5";
sheet = 1;

germany = spreadSheetReadM(fname, range, sheet);

Now you will have a GAUSS variable in your workspace named germany, you can print the contents of this matrix like this:

print germany;

and you should see something like this:

3.200   1.100   2.500
2.800   0.900   1.800
4.100   1.200   0.700
2.900   0.700   0.500

Since this matrix is now in your GAUSS workspace, you can use it in your computations. For example, after loading germany as we did above, you could do something like this if you wanted to:

//Extract all rows of 1st and second
//columns of 'germany' into new variable
x_and_y = germany[., 1:2];

//Calculate correlation coefficient
print corrx(x_and_y);

Alternatively, you could save the data in a format that is more convenient to load into GAUSS, such as a GAUSS dataset or a GAUSS matrix file. For example, to save all columns of germany, you would enter:

save germany;

then to load it into GAUSS later, you would only need to enter:

load germany;

aptech

1,773

Your Answer

1 Answer

0

You can load the columns in as separate GAUSS variables, or as a matrix. For example, if we have an Excel spreadsheet that looks like this:

Year     X     Y     Z
1989   3.2   1.1   2.5
1990   2.8   0.9   1.8
1991   4.1   1.2   0.7
1992   2.9   0.7   0.5

where the cell A1 contains Year, B1 contains X, C1 contains Y, B2 contains 3.2, C2 contains 1.1, etc. Let's further suppose that this data is on the first sheet of an Excel file named german_data.xlsx. You can create one GAUSS matrix named germany that contains the data from X, Y and Z like this:

fname = "german_data.xlsx";
range = "B2:D5";
sheet = 1;

germany = spreadSheetReadM(fname, range, sheet);

Now you will have a GAUSS variable in your workspace named germany, you can print the contents of this matrix like this:

print germany;

and you should see something like this:

3.200   1.100   2.500
2.800   0.900   1.800
4.100   1.200   0.700
2.900   0.700   0.500

Since this matrix is now in your GAUSS workspace, you can use it in your computations. For example, after loading germany as we did above, you could do something like this if you wanted to:

//Extract all rows of 1st and second
//columns of 'germany' into new variable
x_and_y = germany[., 1:2];

//Calculate correlation coefficient
print corrx(x_and_y);

Alternatively, you could save the data in a format that is more convenient to load into GAUSS, such as a GAUSS dataset or a GAUSS matrix file. For example, to save all columns of germany, you would enter:

save germany;

then to load it into GAUSS later, you would only need to enter:

load germany;

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.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy