Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-05-2016 10:21 AM - edited 05-05-2016 10:23 AM

Hi All,

I am confused about how to arrange my data to run a probit model. I am aware the model needs to be run in another package other than IML (namely QLIM), but I thought it would be easiest to arrange the data using IML.

I have data on 484 farms over 132 months for four variables. Currently, I have each variable in its own matrix as follows:

Here is the Quantity Matrix:

** Month_1 Month_2 .... Month_j**

**Farm_1** Q_1_1 Q_1_2 Q_1_j

**Farm_2 **Q_2_1 Q_2_2 Q_2_j

. .

.

.

**Farm_i **Q_i_1 Q_i_2 Q_i_j

I have matrices of equal dimensions for prices, variable costs, and total costs. Column j represents the j'th month and row i represents the i'th farm in each matrix.

If anyone can give me some guidance about how to arrange this data, I would greatly appreciate it. Thanks!!

Accepted Solutions

Solution

05-05-2016
10:52 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to NCSU_2016

05-05-2016 10:50 AM

Use the COLVEC function to create a single vector from each matrix. Then save the data to a SAS data set, along with indicator variables for the MONTH and FARM variables. This is called transforming the data from "wide to long" form. You might like to read the article "Plotting multiple time series in SAS/IML."

You can use the ROW and COL functions to easily create the indicator variables, as follows:

```
proc iml;
/* 4 months (columns) and 3 farms (rows) */
Q = {1 2 3 4,
5 6 7 8,
9 10 11 12};
Qvec = colvec(Q);
Farm = colvec(row(Q));
Month = colvec(col(Q));
print Farm Month QVec;
```

All Replies

Solution

05-05-2016
10:52 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to NCSU_2016

05-05-2016 10:50 AM

Use the COLVEC function to create a single vector from each matrix. Then save the data to a SAS data set, along with indicator variables for the MONTH and FARM variables. This is called transforming the data from "wide to long" form. You might like to read the article "Plotting multiple time series in SAS/IML."

You can use the ROW and COL functions to easily create the indicator variables, as follows:

```
proc iml;
/* 4 months (columns) and 3 farms (rows) */
Q = {1 2 3 4,
5 6 7 8,
9 10 11 12};
Qvec = colvec(Q);
Farm = colvec(row(Q));
Month = colvec(col(Q));
print Farm Month QVec;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

05-05-2016 10:52 AM

Wow, thanks Rick. You are a wonderful help every time. I appreciate your expertise!