How to run a function for each id (in unbalanced panel data).

조회 수: 2 (최근 30일)
Ricardo Henriquez
Ricardo Henriquez 2022년 9월 19일
댓글: Stephane Dauvillier 2022년 9월 19일
Hello,
I am brand new in matlab, and I would like to run a function (user-written) for each id in a unbalanced panel database (N x T) .
The function is the Shanken correction (1992) to get EIV-bias free estimates. What I am struggling with is to loop the function for every id. Or the otherway around, to split the data by id to run the function in each split?
Any ideas how to deal with this?
  댓글 수: 1
Stephane Dauvillier
Stephane Dauvillier 2022년 9월 19일
Hi Ricardo,
I'm not sure I've understood your question.
If you want to apply a function for each value of identification, for example if you have an id vector and a vector of exapense and you want to compute the have the sum of expense you can use the function splitapply.
id = [ 1; 2; 1; 1; 2; 3];
expense = [10; 5;20; 8;90;88];
sumPerId = splitapply( @sum, expense, id) ;
% sumPerId will be equal 10+20+8 = 38 for id1
% 5+90 = 95 for id2
% 88 = 88 for id3
Is this what you want to do ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by