Dear all,
I was just thinking about this: When you analyze hierarchical structured dataset (for example students L1 clustered in schools L2) and you wish to analyze the second level only (by aggregation of the first level values) you probably use the command -collapse- which gives you for example mean, median or SD etc. of the L1 units to the L2 units, but it create new dataset.
Now, I was trying to figure out a way around this, so you can incorporate the results of -collapse- into your original dataset. I would use the command:
- by L2_var, sort: egen new_L2_var = mean(another_variable) -
the result of this command is that each L1 unit gets a new mean value of the variable of interest (which is completely correct). And what I was thinkg about -- can you keep just on value for each L2 unit created this way so you have de facto two datasets in one? I don't know how to write a code for this (but I assume it will mostlikely say: keep the first value of certain variable by group).
Does it make sense to you?
Thanks for your thoughts.
Related Posts with Command collapse AND keeping the original dataset
Plot of Interaction TermI am trying to use margins and marginsplot to plot the effect of X1 in a regression as follows: Y=a…
tvgc - time-varying granger causalityHow can I solve this error in Stata? tvgc_cv(): 3499 mm_quantile() not found <istmt>: - funct…
Creating a loop to count the weeks before and after a policyHi, I'm working on understanding the impact of a hospital policy on healthcare utilization. The pol…
How to modify individual graph's title on combined graphDear Stata users, Suppose we have a combined graph that is composed of two individual graphs, let's …
Survival analysis with inverse probability weighting after multiple imputationDear Statalist-users, Hopefully, there is someone who can help me with the following: I'm trying to…
Subscribe to:
Post Comments (Atom)
0 Response to Command collapse AND keeping the original dataset
Post a Comment