# Using cross-sectional data for OLS/logit models

I have a cross-sectional dataset with the data example below, where the variable (id) refers to each individual in the df and rows represent the different number of Reddit posts written by each username, which vary across individuals. My goal is to use OLS regression to predict average sentiment, based on individual-level covariates which are all measured at the username-level. For instance, the indicator "collective_action_prop" counts the proportion of collective action mentions across all posts for a given username.

Currently, I ran the OLS model as follows:

regress avg_sentiment avg_response collective_action_prop economic_demand_prop


However, I am not sure if I am correctly running the OLS regression at the username-level with the current data structure where each row represents a Reddit post but the variable id refers to usernames:


clear
input float id double avg_sentiment float avg_response double(collective_action_prop economic_demand_prop)
1                 -1         1                  0                 1
2                 -1         0                  0                 1
3                  0         0                  0                 0
4                  0         .                  0                 0
4                  0         .                  0                 0
5                  1         6                  0                 0
6 -.2105263157894737  .2105263                  0 .2631578947368421
6 -.2105263157894737  .2105263                  0 .2631578947368421
6 -.2105263157894737         .                  0 .2631578947368421
6 -.2105263157894737         .                  0 .2631578947368421
6 -.2105263157894737         .                  0 .2631578947368421
6 -.2105263157894737  .2105263                  0 .2631578947368421
6 -.2105263157894737  .2105263                  0 .2631578947368421
6 -.2105263157894737  .2105263                  0 .2631578947368421
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
7 -.2307692307692307  .6923077 .07692307692307693 .3461538461538461
end
----
$$$$

• Are you using avg_sentiment for convenience or because you don't know the value of sentiment associated with each individual post? Feb 22 at 11:27
• Good question, for convenience where I am trying to estimate average sentiment at the reddit username-level. Feb 22 at 14:52
• In that case, I would suggest individual post sentiment as your response variable, as this would give you a measure of how much sentiment varies from post to post, once you have accounted for everything else. Also, this looks like a natural setup for a random-effects model, as you would expect the correlation between posts by the same user to be higher than the correlation between posts of different users. This also takes care of the fact that some users post more than others. Feb 22 at 16:23
• Thanks for the feedback! So it makes sense to use sentiment per post as the outcome, with controls like avg_response or collective_action_prop that are measured at the individual-level, rather than post-level? I ask because I thought that my unit of analysis (e.g. username or post) has to be consistent across both my Y and control variables. Feb 22 at 17:30
• Yes, that's totally fine. I'll post a proper answer. Feb 22 at 17:45

In your case this would look like $$y_{ij} = \beta_0 + \beta_1 x_j + u_j + \varepsilon_{ij}$$ where $$y_{ij}$$ is the sentiment for the $$i$$th post by user $$j$$, $$x_j$$ is a covariate at the individual level (you can have more than one, obviously), $$u_j \sim \mathcal{N}(0, \sigma^2_u)$$ are the random intercepts, and $$\varepsilon_{ij} \sim \mathcal{N}(0, \sigma^2_\varepsilon)$$ are the error terms.
• Ah, good point. Here's the full list: stata.com/features/panel-longitudinal-data The approach I suggested is a linear model with random intercepts. It's been a while since I used Stata, but I think it's the xtreg function with the re` option. Feb 22 at 19:43