Saving break years after structural break test

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

pras
Posts: 5
Joined: Fri May 24, 2024 1:53 pm

Saving break years after structural break test

Postby pras » Thu May 30, 2024 7:56 am

Hello everyone,

I am very new with EViews. Can you help me how to save the years from the structural break test? Here is my simple code and attached is the sample data. The output that I aim is dummy variable for the years when structural break take place for each country/variable. Thank you.

Code: Select all

%country = "BGD IND LKA MDV PAK" ' Loop through each dependent variable and run the regression for %y {%country} ' Create an equation object with a dynamic name equation eq_{%y} ' Estimate the regression eq_{%y}.ls {%y} c year ' Run multibreak test eq_{%y}.multibreak c year next
Best regards,

Pras
Attachments
sample.xlsx
(11.54 KiB) Downloaded 2956 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Saving break years after structural break test

Postby EViews Gareth » Thu May 30, 2024 8:06 am

You could estimate via breakls instead of using the breaktest, and then store the break points.

Code: Select all

%country = "BGD IND LKA MDV PAK" ' Loop through each dependent variable and run the regression for %y {%country} equation eq_{%y}.breakls {%y} c year string {%y}_breaks = eq_{%y}.@breaks next

pras
Posts: 5
Joined: Fri May 24, 2024 1:53 pm

Re: Saving break years after structural break test

Postby pras » Thu May 30, 2024 9:56 am

Hello Gareth,

Thank you your help. Is there any way I can export the string into excel? Ideally I need to have an excel table where the rows are the year and the columns are each country/variable, with value = 1 if the year is equal to the break year. If that is not possible with EViews, at least I need to combine all the resulting string into one group and then export them to excel. At the moment, I am manually adding the break year dummy in excel, but it's time consuming and error-prone. Sorry if my question is too basic. Thank you.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Saving break years after structural break test

Postby EViews Gareth » Thu May 30, 2024 11:36 am

You can make a table object, insert the information you want into the table object, then save the table to disk as an Excel file, or csv.

pras
Posts: 5
Joined: Fri May 24, 2024 1:53 pm

Re: Saving break years after structural break test

Postby pras » Thu May 30, 2024 12:36 pm

Thanks, Gareth.

Do I have to fill the table manually as in my simple code below, or is there any way to automate which rows to be changed based on the structural break years? For the way I did it below, it's still time consuming and error-prone. Thanks.

Code: Select all

' Creating the table ' Step 1: Define the number of years scalar startYear = 1990 scalar endYear = 2022 scalar numYears = endYear - startYear + 1 ' Step 2: Create a table with the appropriate number of rows and 6 columns table (numYears + 1, 6) mytable ' +1 for the header row ' Step 3: Name the columns mytable(1, 1) = "index" mytable(1, 2) = "year" mytable(1, 3) = "BGD" mytable(1, 4) = "IND" mytable(1, 5) = "LKA" mytable(1, 6) = "MDV" mytable(1, 7) = "PAK" ' Step 4: Fill the "Year" column with the range of years for !i = 1 to numYears mytable(!i + 1, 1) = !i ' Fill the index column mytable(!i + 1, 2) = startYear + !i - 1 ' Fill the year column next ' Filling the break years dummy for BGD mytable(13, 3) = "1" mytable(20, 3) = "1" mytable(24, 3) = "1" mytable(28, 3) = "1"

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Saving break years after structural break test

Postby EViews Gareth » Thu May 30, 2024 12:51 pm

Entirely depends on what you want it to look like in Excel. But the simplest is probably something like:

Code: Select all

table mytable %country = "BGD IND LKA MDV PAK" !row = 2 ' Loop through each dependent variable and run the regression for %y {%country} equation eq_{%y}.breakls {%y} c year %breaks = eq_{%y}.@breaks mytable(!row,1) = %y !col = 2 for %j {%breaks} mytable(!row, !col) = %j !col = !col+1 next !row=!row+1 next

pras
Posts: 5
Joined: Fri May 24, 2024 1:53 pm

Re: Saving break years after structural break test

Postby pras » Thu May 30, 2024 3:33 pm

Thanks a lot, Gareth.

If there are no break years, the code returns an error. I think I need to modify this code:

Code: Select all

!col = 2 for %j {%breaks} mytable(!row, !col) = %j !col = !col+1 next


I tried the following, but still returning error. Could you please help, Gareth? Thanks a lot!

Code: Select all

!col = 2 if {%breaks} <> "" then for %j {%breaks} mytable(!row, !col) = %j !col = !col+1 next else mytable(!row, !col) = "" endif

pras
Posts: 5
Joined: Fri May 24, 2024 1:53 pm

Re: Saving break years after structural break test

Postby pras » Thu May 30, 2024 3:43 pm

Hello Gareth,

I think I found the solution as follows. Thanks for your help.

Code: Select all

!col = 2 if @len(%breaks) > 0 then for %j {%breaks} mytable(!row, !col) = %j !col = !col+1 next else mytable(!row, !col) = "" ' Fill empty cells in case of no breaks endif


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest