heteroskedasticity-consistent (HC) standard errors

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)

by NathalieGier » Sat Jun 13, 2020 9:33 am

Hi together,
I recognized that some of my predictors does not fulfill the assumption of homoskedasticity.
As far as I know, robust standard errors or heteroskedasticity-consistent (HC) standard errors are one possibility to cope with this issue.

Is there any possibility to compute a regression analysis with such HC standard errors? I have already downloaded the module walrus, but can only find t-tests and anova.

Thanks in advance & regards from Germany

Nathalie
NathalieGier
 
Posts: 1
Joined: Sat Jun 13, 2020 9:22 am

by jonathon » Fri Jul 03, 2020 7:30 am

hi,

not something i know about, sorry.

kind regards

jonathon
User avatar
jonathon
 
Posts: 1689
Joined: Fri Jan 27, 2017 10:04 am

by MAgojam » Sat Jul 04, 2020 12:35 am

Hi, @NathalieGier.
I am attaching a jamovi file where with a small scrip r for the Rj module you can calculate heteroskedasticity-consistent (HC) standard errors as in STATA.

incoming_saving.omv
(97.32 KiB) Downloaded 134 times

I hope you find it useful, let me know.

Regards from Italy.
Maurizio
User avatar
MAgojam
 
Posts: 145
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

by tkemeny » Wed Feb 17, 2021 11:50 am

Hi @Magojam et al,

It is very odd that robust SEs are not a feature, seeing as they are so commonly used.

I tried your code, but it seems to just output the same set of non-robust standard errors. See attached.

Screenshot 2021-02-17 at 11.47.43.png
Screenshot 2021-02-17 at 11.47.43.png (51.46 KiB) Viewed 888 times
Screenshot 2021-02-17 at 11.48.01.png
Screenshot 2021-02-17 at 11.48.01.png (220.07 KiB) Viewed 888 times


Any thoughts?
Thanks
Tom
tkemeny
 
Posts: 23
Joined: Mon Sep 07, 2020 2:57 pm

by MAgojam » Thu Feb 18, 2021 4:14 pm

Hi Tom.
I am attaching you .omv files with Rj scripts and screenshots that should help.
For the script's summary.lm () function that overrides summary (), take a look here:
https://economictheoryblog.com/2016/08/07/robust-standard-errors-in-r-function/
Sorry if I run, but if it doesn't help, go back.
Rj_robust_stderr.omv
(5.58 KiB) Downloaded 21 times

Rj_robust_stderr.PNG
Rj_robust_stderr.PNG (159.55 KiB) Viewed 625 times

Cheers,
Maurizio
User avatar
MAgojam
 
Posts: 145
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

by tkemeny » Tue Feb 23, 2021 3:41 pm

Thanks so much. The code is failing on something very simple - I'm not sure how to refer to the data - forgive me, I'm a Stata person, not an R person.

If I want to run the code on an open Jamovi dataset (.omv), how do I do that? I tried something like

Code: Select all
my_data <- lab_data_baseline.dta ('/Users/tk1/Dropbox/teaching/BUS135_QUANT/data/lab_data_baseline.dta')
my_model <- lm(grsswk ~ sexx + ttushr + sc10mmj, data = my_data)


But this returns an error. I'm sure this is completely simple but I'm not how to solve it.

Thanks
Tom
tkemeny
 
Posts: 23
Joined: Mon Sep 07, 2020 2:57 pm

by MAgojam » Wed Feb 24, 2021 8:51 am

Hi, Tom.
Sorry if I tell you things you know, but I don't wish I had misinterpreted your question.

The Stata files (.dta), are files that jamovi is able to import without particular problems by going from the Import->This PC (Hamburger menu).
From the combobox Data files select one of the available formats, in your case it will be Stata files (.dta) and then with Browse go to the folder where the file you want to use is present.
In the Rj editor, you can refer to the dataset with data.
Code: Select all
# Your code:
my_data <- lab_data_baseline.dta ('/Users/tk1/Dropbox/teaching/BUS135_QUANT/data/lab_data_baseline.dta')
my_model <- lm(grsswk ~ sexx + ttushr + sc10mmj, data = my_data)

# it should be this:
my_data <- data
my_model <- lm(grsswk ~ sexx + ttushr + sc10mmj, data = my_data)

# or even just this:
my_model <- lm(grsswk ~ sexx + ttushr + sc10mmj, data = data)


If you prefer to use the Rj editor with a blank jamovi, you can refer to your Stata data with this lightweight code:
Code: Select all
library(haven)
library(lmtest)

# Import Stata file
my_data  <- read_dta('C:/Users/tk1/Dropbox/teaching/BUS135_QUANT/data/lab_data_baseline.dta')
my_model <- lm(grsswk ~ sexx + ttushr + sc10mmj, data = my_data)


Cheers,
Maurizio
User avatar
MAgojam
 
Posts: 145
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

by tkemeny » Fri Feb 26, 2021 10:05 am

Again, many thanks Maurizio - I really appreciate your help.

I copied and pasted your code (adjusting the path slightly - I'm on a Mac not a pc), but no matter how I adjust, or which version of your code I use, literally nothing happens. I get no output, and no error.

For instance- running the following:
Code: Select all
library(haven)
library(lmtest)

# Import Stata file
my_data  <- read_dta('/Users/tk1/Dropbox/teaching/BUS135_QUANT/data/lab_data_baseline.dta')
my_model <- lm(grsswk ~ sexx + ttushr + sc10mmj, data = my_data)


I get the attached output (nothing). I also tried this with the data already loaded. Same non-result.

So confusing! Any thoughts?

Best,
Tom
Attachments
Screenshot 2021-02-26 at 10.04.03.png
Screenshot 2021-02-26 at 10.04.03.png (100.6 KiB) Viewed 349 times
tkemeny
 
Posts: 23
Joined: Mon Sep 07, 2020 2:57 pm

by jonathon » Fri Feb 26, 2021 10:38 am

put

my_model

on a line at the end by itself.

jonathon
User avatar
jonathon
 
Posts: 1689
Joined: Fri Jan 27, 2017 10:04 am

by MAgojam » Fri Feb 26, 2021 9:42 pm

Hi Tom.
I saw that Jonathon has already answered you (thanks J).
I think he will help you to have the file (attached) with all the code again (to answer the original question).
Check that the file path is correct for your MAC.
If there are any problems, come back here.

Rj_robust_stderr.omv
(2.03 KiB) Downloaded 21 times

Cheers,
Maurizio
User avatar
MAgojam
 
Posts: 145
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Next

Return to Help