Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str10 A str45 B str17 C str29 D str23 E str28 F str45 G str14 H " " "ERROR" "ADEVINTA" "ADEVINTA - TURNOVER BY VOLUME" "ADEVINTA - MARKET VALUE" "ADEVINTA - PRICE TO BOOK VAL" "ERROR" "AF GRUPPEN 'A'" "Code" "" "N:ADEB(P)" "N:ADEB(VO)" "N:ADEB(MV)" "N:ADEB(PTBV)" "" "N:AFG(P)" "ISIN" "NO0010844038" "NO0010844038" "NO0010844038" "NO0010844038" "NO0010844038" "NO0003078107" "NO0003078107" " 6/30/2017" "$$ER: E100,INVALID CODE OR EXPRESSION ENTERED" "NA" "NA" "NA" "NA" "$$ER: E100,INVALID CODE OR EXPRESSION ENTERED" "150" " 7/3/2017" "" "NA" "NA" "NA" "NA" "" "150" " 7/4/2017" "" "NA" "NA" "NA" "NA" "" "149.5" end
In order to reshape the data as done by David Benson in this post: https://www.statalist.org/forums/for...gaCLup2Du7ebZY
I first need to add prefixes to the different ISIN-codes (to ensure unique variable names), and then make these the variable names.
I am struggling with creating a loop that e.g. starts at the 3rd column, and for every 5th column adds "n_" to each observation in line/row 3.
I am able to do this to already defined variable names, but i need to rename the data in row 3 before i define it as variable names, in order to ensure unique variable names.
I have tried writing the following code:
Code:
d, s return list unab varlist : * tokenize "`varlist'" forval j = 3(5)`r(k)'{ rename ``j'' p_``j'[3]' }
I have tried not tokenizing "varlist", using only:
Code:
forval j = 3(5)`r(k)' { rename `j' ``j'[3]' }
Does anybody know how to make this work?
Best regards,
Axel
0 Response to Add prefix on every Nth column in row X in panel data. Then, make row X the new variable names.
Post a Comment