字符串拆分重塑

时间:2018-11-17 12:38:48

标签: stata

我正在尝试对数据进行很长的重塑:

clear
input byte id float(v_az032_2017 v_az033_2017 v_az032_2018 v_az033_2018)
1 27.484943 27.324594  27.36449  27.32548
2  27.67231  27.32464 27.383556 27.325926
3 27.325935  27.32939 27.334106  27.32985
4  27.53663  27.32457   27.3705  27.33671
5 27.328493 27.325037 27.335546  27.33038
end

我已经查阅了以下页面,但到目前为止我还没有成功:

  1. Double reshape long
  2. Problems with reshape

如何重塑数据,使其看起来像这样:

id year   h      v  
 1 2017 az032 27.48494  
 1 2018 az032 27.36449  
 1 2017 az033 27.32459  
 1 2018 az033 27.32548  
 2 2017 az032 27.67231  
 2 2018 az032 27.38356  
 2 2017 az033 27.32464  
 2 2018 az033 27.32593 

1 个答案:

答案 0 :(得分:2)

实际上,您只需<script src="https://api.mapbox.com/mapbox.js/plugins/leaflet-pip/v0.0.2/leaflet-pip.js"></script> <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script> <link href="https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css" rel="stylesheet" /> <script src="https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js"></script> <form class="form"> <label for="latitude">Latitude:</label> <input id="latitude" type="text" /> <label for="longitude">Longitude:</label> <input id="longitude" type="text" /> </form> <div id="map" style="width: 800px; height: 500px; "></div>一次。

然后,您可以简单地reshape long split生成的(复合)变量和year

rename

reshape long v_, i(id) j(az_year) string

split az_year, generate(var) parse("_")
drop az_year

rename v_ v
rename var1 h
rename var2 year

order id year h v
相关问题