Statistical programming, matrix languages, and more

Organize Panel Data in IML

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Organize Panel Data in IML

[ Edited ]

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
SAS Super FREQ
Posts: 3,415

Re: Organize Panel Data in IML

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;

View solution in original post


All Replies
Solution
‎05-05-2016 10:52 AM
SAS Super FREQ
Posts: 3,415

Re: Organize Panel Data in IML

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;
Occasional Contributor
Posts: 13

Re: Organize Panel Data in IML

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 247 views
  • 0 likes
  • 2 in conversation