Essentially, I have a data set where it looks something like this (I made the actual numerical values up, but the actual has a lot more rows). I am using Stata 11.
Culture | Independent Variable | Dependent Variable |
1 | 1.5 | 3 |
2 | 2 | 4 |
3 | 1 | 2 |
3 | 5 | 4 |
2 | 9 | 3 |
2 | 8 | 5 |
1 | 4 | 2 |
3 | 3 | 2 |
1 | 2 | 5 |
I then wanted to do a correlation only among those with the culture value == 1 (so that I can do a correlation between the IV and DV only for those belonging to a certain culture), and here is where I get stuck. I tried multiple variations of if statements, e.g. pwcorr IV DV, star (0.05) if culture == 1. or if culture ==1, pwcorr IV DV, star (0.05). they dont seem to work, but I try bysort (culture): pwcorr IV DV, star (0.05) and it does!
so my questions are:
a) I find if statements pretty confusing in Stata, and have been reading a bunch of articles online to no avail. Not sure if anyone can point me to a beginner friendly explanation on whether I can even use if statements (in the classic way) because Stata seems to have very constricted options for if
b) why is there a need to do bysort for my data set - i.e., wouldn't by just work? couldn't Stata just correlate based on my by category? Why is the sort function necessary?
Thank you so much! Much, much appreciated for a newbie.
Jen
0 Response to Newbie question - Understanding the bysort command, theoretically
Post a Comment