Count number of dummy variables

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

Andrew_Gillich
Posts: 1
Joined: Fri May 13, 2022 7:32 am

Count number of dummy variables

Postby Andrew_Gillich » Wed Aug 02, 2023 10:14 am

Hi,

I have a dummy variable that is either 1 or NA called "below50". I want to create a series that counts how many consecutive 1's there are and returns to 0 when it encounters an NA.

EX:
below50 CUM
NA 0
NA 0
NA 0
1 1
1 2
1 3
1 4
NA 0
NA 0
NA 0
1 1
NA 0

As a second job I would also like to see this CUM series count in reverse so that if below50 is NA, it counts how many consecutive NAs there are but incrementing from -1, -2, -3 etc...

Ex:

EX:
below50 CUM2
NA -1
NA -2
NA -3
1 1
1 2
1 3
1 4
NA -1
NA -2
NA -3
1 1
NA -1

EViews Matt
EViews Developer
Posts: 564
Joined: Thu Apr 25, 2013 7:48 pm

Re: Count number of dummy variables

Postby EViews Matt » Thu Aug 03, 2023 11:20 am

Hello,

Try these...

Code: Select all

series cum = @recode(@isna(below50), 0, @nan(cum(-1), 0) + 1)
series cum2 = @recode(@eqna(below50,below50(-1)), @nan(cum2(-1), 0), 0) + @recode(@isna(below50), -1, 1)


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 17 guests