Open kirstenronning opened 3 years ago
Update: I added data$
in front of the objects in the regression code, and I changed Post_Treatment
to data$Post
. Hoping this is a solid solution as it ran!
You also could have included the option, data = data to the end of your regression command:
Like this: reg <- lm( Vandalism ~ Group + Post_Treatment + Group Post_Treatment , data = data*)
On Mon, Jul 12, 2021 at 2:23 PM kirstenronning @.***> wrote:
Update: I added data$ in front of the objects in the regression code, and I changed Post_Treatment to data$Post. Hoping this is a solid solution as it ran!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DS4PS/cpp-525-sum-2021/issues/3#issuecomment-878606590, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBYFNO3RQK3PREYI6ELTXNMOPANCNFSM5AHTW2VA .
I also have the same problem for hours, I have edited the regression command like you mentioned but I still get this error.
@radwan-a You may want to try removing the asterisks after "Group*Post_Treatment" line 44 and "data" line 45. I think r is expecting another variable in the first case and in the second case it references the wrong dataset.
Try changing Post_treatment
to Post
Hi Radwan,
you have an asterisk at the end of Post_Treatment, and data
so lines 44 and 45 should be this
reg <- lm ( Vandalism ~ Group + Post_Treatment + Group*Post_Treatment, data = data )
As a style note. I use dat (not data) as the default name of my data table because I'm trying to avoid the confusion that comes from lines like data = data
On Mon, Jul 12, 2021 at 10:47 PM radwan-a @.***> wrote:
I also have the same problem for hours, I have edited the regression command like you mentioned but I still get this error.
[image: Screen Shot 2021-07-13 at 12 46 44 AM] https://user-images.githubusercontent.com/70247574/125397627-79ab0d80-e3ae-11eb-9d8e-86ad268eb7e3.png
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DS4PS/cpp-525-sum-2021/issues/3#issuecomment-878797737, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBZPUBNZCBDEUMOCYKTTXPHN7ANCNFSM5AHTW2VA .
Another student had told you to try Post and not Post_treatment.
When you did it said you had an incomplete string, which is a different error. Instead of knitting the document, try running the code chunk it should tell you what line the error is occurring on rather than identifying that this chunk has an error.
It looks like there is a floating ` at the end of your stargazer command. Try removing it
If that does not work can you post the code next so I can trouble shoot it? Taking a screenshot makes it tough to recreate the error
On Tue, Jul 13, 2021 at 12:35 PM radwan-a @.***> wrote:
@Dselby86 https://github.com/Dselby86 I have tried that as well and still getting the same error.
[image: Screen Shot 2021-07-13 at 2 34 39 PM] https://user-images.githubusercontent.com/70247574/125514095-6acb8797-6f12-4e92-83f7-805af2986da8.png
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/DS4PS/cpp-525-sum-2021/issues/3#issuecomment-879347048, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHB4KGKJNWYKM745ETJDTXSIOLANCNFSM5AHTW2VA .
You need to load packages before using functions that they contain.
This is a weird one because %>% is an operator (the pipe operator) and not a regular function, but it is contained inside the dplyr package. If you load the packages the rest of the code works.
library( stargazer )
library( dplyr )
library( pander )
URL <- "https://raw.githubusercontent.com/DS4PS/pe4ps-textbook/master/labs/DATA/diff-in-diff-lab.csv"
data <- read.csv( URL, stringsAsFactors=F )
head( data ) %>% pander()
reg <- lm ( Vandalism ~ Group + Post + Group*Post,
data = data )
stargazer( reg,
type = "text",
dep.var.labels = c("Vandalism"),
column.labels = c(""),
covariate.labels = c("Intercept (B0)",
"Treatment Group (B1)",
"Post-treatment (B2)",
"Diff in Diff (B3)"),
omit.stat = "all",
digits = 0,
intercept.bottom = FALSE )
I changed output from HTML to TEXT for previewing purposes, but you will want to change it back to type="html" before knitting.
stargazer( reg,
type = "html",
dep.var.labels = c("Vandalism"),
column.labels = c(""),
covariate.labels = c("Intercept (B0)",
"Treatment Group (B1)",
"Post-treatment (B2)",
"Diff in Diff (B3)"),
omit.stat = "all",
digits = 0,
intercept.bottom = FALSE )
What you are seeing is the HTML code for the regression table. Your R Markdown document will convert it into a pretty table when you knit the document.
type="text" is useful for previewing the table if you are running a code interactively, but if you leave that as the output type it will not look very professional in your final document.
Note that you need an extra argument in your code chunk for the HTML version to work. results="asis" tells R to not add the ## at the start of each line.
```{r, results="asis"}
# your code here
When knitting R will first run all of the chunks and embed the output in the markdown document, then it converts the markdown document into an HTML document, word document, PDF, or whatever format you have chosen as the output.
The results="asis" argument means the HTML code will be added directly to the document (instead of printed as R output), and during the knitting phase all HTML code is then rendered (markdown documents understand HTML as well).
I am trying to run the regression in R, but I am getting an error. When trying to replicate the code in the Lecture Notes, I also received this error in the "2 A Difference-in-Difference model" example, but I somehow managed to get it to work in the "3 Replication of a study" example.
Here is my code:
This is the error message:
Error in eval(predvars, data, env) : object 'Vandalism' not found
I have tried to add "data$Vandalism", "data$Group", etc. to all of the objects, but then I get this error:
Error in model.frame.default(formula = data$Vandalism ~ data$Group + data$Post_Treatment + : invalid type (NULL) for variable 'data$Post_Treatment'
I have also cleaned out the global environment multiple times trying to troubleshoot this.