Dear all,
From the variable v I would like to generate 3 variables: v1, v2, v3. Given that these are the 3 observations of v. I need to make separate calculations with them, therefore I need to cut this variable as many times as its observations. Of course I can write:
gen v1 = v[1]
gen v2 = v[2]
gen v3 = v[3]
although I have more that 3 and therefore I look for a proper loop, I have tried the following:
forvalues i = 1/_n {
gen v`i'= v[_n-`i']
}
but it has a syntax error that I cannot fix. Generally whenever I enter `i' inside brackets in such commands I get an error. Could anyone suggest a solution or a different loop that I can use?
Thanks is advance,
Shadi
Related Posts with generating separate variables from one variables's observations, is there a loop?
reshapingDear statalist members, I would like to seek your advice on how to reshape/transpose data. Details a…
Parallel trends for difference-in-difference models with multiple periodsDear colleagues, I would appreciate if you may advise me on how to test for parallel trends in Stat…
dropping variablesHi all, I have daily stock returns in my dataset. One of the variables is the stock identifier (so f…
Chi-square test weighted sum of squared residualsHello Statalisters, I run the WLS regression: Code: reg salary edu sex [aw = inv_var] Where inv…
How to install rdobDear Statlist community, for an university assignment I need to replicate the findings of a paper (M…
Subscribe to:
Post Comments (Atom)
0 Response to generating separate variables from one variables's observations, is there a loop?
Post a Comment